Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] CI/CD for numscript release #86b37qfxt #2

Merged
merged 35 commits into from
Jan 23, 2025

Conversation

debora-be
Copy link

@debora-be debora-be commented Dec 27, 2024

User description

WASM Build and Release Pipeline

This PR adds WASM build support via TinyGo and implements an automated release pipeline for the compiled WASM files.

Changes

CI/CD Pipeline

  • Added TinyGo build step in release workflow
  • Configured GitHub Actions to create releases and attach WASM builds
  • Set Go version to 1.21 for TinyGo compatibility

Build Configuration

  • Added .gitignore entries to exclude WASM builds
  • Fixed Go version compatibility issues with TinyGo

Release Management

  • Added release workflow to automatically create GitHub releases
  • Configured WASM file upload to releases
  • Implemented download script for fetching WASM builds

Development Environment

  • Added Nix development environment configuration
  • Added direnv support for automatic environment loading

Testing

The changes can be tested by:

  1. Running the CI pipeline locally with act
  2. Using the download script: ./scripts/download-wasm.sh

Notes

  • WASM builds are not included in the repository and must be downloaded from releases

PR Type

enhancement, configuration changes


Description

  • Added a script to download numscript.wasm from GitHub releases, supporting both latest and specific version downloads.
  • Updated the CI/CD pipeline to include TinyGo installation and WASM build steps, ensuring compatibility with Go 1.21.5.
  • Configured GitHub Actions to automatically upload WASM builds as release artifacts.
  • Introduced a Nix flake for setting up the development environment, including necessary dependencies and shell hooks.

Logs

Local ran of the release pipeline with success status:

[Release/release]   💬  ::debug::Exe path is /opt/hostedtoolcache/goreleaser-action/2.5.1/x64/goreleaser
| GoReleaser latest installed successfully
| [command]/opt/hostedtoolcache/goreleaser-action/2.5.1/x64/goreleaser release --snapshot
|   • skipping announce, publish and validate...
|   • loading environment variables
|   • getting and validating git state
|     • ignoring errors because this is a snapshot     error=git doesn't contain any tags. Either add a tag or use --snapshot
|     • git state                                      commit=dbf61041ff44e14af0c046c0acf6f6e3c885049f branch=feat/ci-cd-for-numscript#86b37qfxt current_tag=v0.0.0 previous_tag=<unknown> dirty=false
|     • pipe skipped                                   reason=disabled during snapshot mode
|   • parsing tag
|   • setting defaults
|   • snapshotting
|     • building snapshot...                           version=0.0.0-SNAPSHOT-dbf6104
|   • running before hooks
|     • running                                        hook=go mod tidy
|   • ensuring distribution directory
|   • setting up metadata
|   • writing release metadata
|   • loading go mod information
|   • build prerequisites
|   • building binaries
|     • building                                       binary=dist/numscript-wasm_wasip1_wasm/numscript.wasm
|     • running hook                                   hook=mkdir -p /home/d/Downloads/numscript-wasm/dist/numscript-wasm_wasip1_wasm
|     • took: 45s
|   • archives
|     • archiving                                      name=dist/numscript-wasm_ 0.0.0-SNAPSHOT-dbf6104_Wasip1_wasm.tar.gz
|   • calculating checksums
|   • writing artifacts metadata
|   • release succeeded after 47s
|   • thanks for using GoReleaser!
[Release/release]   ❓  ::group::Artifacts output
| [{"name":"metadata.json","path":"dist/metadata.json","internal_type":30,"type":"Metadata"},{"name":"numscript.wasm","path":"dist/numscript-wasm_wasip1_wasm/numscript.wasm","goos":"wasip1","goarch":"wasm","target":"wasip1_wasm","internal_type":4,"type":"Binary","extra":{"Binary":"numscript","Builder":"go","Ext":".wasm","ID":"numscript-wasm"}},{"name":"numscript-wasm_ 0.0.0-SNAPSHOT-dbf6104_Wasip1_wasm.tar.gz","path":"dist/numscript-wasm_ 0.0.0-SNAPSHOT-dbf6104_Wasip1_wasm.tar.gz","goos":"wasip1","goarch":"wasm","target":"wasip1_wasm","internal_type":1,"type":"Archive","extra":{"Binaries":["numscript.wasm"],"Checksum":"sha256:3a690bb0f678f12799e3bc0b4edafd43633f3400a5bf4be14707c3a77184a964","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"numscript-wasm_0.0.0-SNAPSHOT-dbf6104_checksums.txt","path":"dist/numscript-wasm_0.0.0-SNAPSHOT-dbf6104_checksums.txt","internal_type":12,"type":"Checksum","extra":{}}]
[Release/release]   ❓  ::endgroup::
[Release/release]   ❓  ::group::Metadata output
| {"project_name":"numscript-wasm","tag":"v0.0.0","previous_tag":"","version":"0.0.0-SNAPSHOT-dbf6104","commit":"dbf61041ff44e14af0c046c0acf6f6e3c885049f","date":"2025-01-13T01:28:45.783189023Z","runtime":{"goos":"linux","goarch":"amd64"}}
[Release/release]   ❓  ::endgroup::
[Release/release]   ✅  Success - Main Run GoReleaser
[Release/release]   ⚙  ::set-output:: artifacts=[{"name":"metadata.json","path":"dist/metadata.json","internal_type":30,"type":"Metadata"},{"name":"numscript.wasm","path":"dist/numscript-wasm_wasip1_wasm/numscript.wasm","goos":"wasip1","goarch":"wasm","target":"wasip1_wasm","internal_type":4,"type":"Binary","extra":{"Binary":"numscript","Builder":"go","Ext":".wasm","ID":"numscript-wasm"}},{"name":"numscript-wasm_ 0.0.0-SNAPSHOT-dbf6104_Wasip1_wasm.tar.gz","path":"dist/numscript-wasm_ 0.0.0-SNAPSHOT-dbf6104_Wasip1_wasm.tar.gz","goos":"wasip1","goarch":"wasm","target":"wasip1_wasm","internal_type":1,"type":"Archive","extra":{"Binaries":["numscript.wasm"],"Checksum":"sha256:3a690bb0f678f12799e3bc0b4edafd43633f3400a5bf4be14707c3a77184a964","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"numscript-wasm_0.0.0-SNAPSHOT-dbf6104_checksums.txt","path":"dist/numscript-wasm_0.0.0-SNAPSHOT-dbf6104_checksums.txt","internal_type":12,"type":"Checksum","extra":{}}]
[Release/release]   ⚙  ::set-output:: metadata={"project_name":"numscript-wasm","tag":"v0.0.0","previous_tag":"","version":"0.0.0-SNAPSHOT-dbf6104","commit":"dbf61041ff44e14af0c046c0acf6f6e3c885049f","date":"2025-01-13T01:28:45.783189023Z","runtime":{"goos":"linux","goarch":"amd64"}}
[Release/release] ⭐ Run Post Set up Go
[Release/release]   🐳  docker exec cmd=[/opt/acttoolcache/node/18.20.5/x64/bin/node /var/run/act/actions/actions-setup-go@v4/dist/cache-save/index.js] user= workdir=
| [command]/opt/hostedtoolcache/go/1.22.10/x64/bin/go env GOMODCACHE
| [command]/opt/hostedtoolcache/go/1.22.10/x64/bin/go env GOCACHE
| /root/go/pkg/mod
| /root/.cache/go-build
[Release/release]   💬  ::debug::Checking zstd --quiet --version
[Release/release]   💬  ::debug::1.4.8
[Release/release]   💬  ::debug::zstd version: 1.4.8
[Release/release]   💬  ::debug::implicitDescendants 'false'
[Release/release]   💬  ::debug::followSymbolicLinks 'true'
[Release/release]   💬  ::debug::implicitDescendants 'false'
[Release/release]   💬  ::debug::omitBrokenSymbolicLinks 'true'
[Release/release]   💬  ::debug::Search path '/root/go/pkg/mod'
[Release/release]   💬  ::debug::Search path '/root/.cache/go-build'
[Release/release]   💬  ::debug::Matched: ../../../../root/go/pkg/mod
[Release/release]   💬  ::debug::Matched: ../../../../root/.cache/go-build
[Release/release]   💬  ::debug::Cache Paths:
[Release/release]   💬  ::debug::["../../../../root/go/pkg/mod","../../../../root/.cache/go-build"]
[Release/release]   💬  ::debug::Archive Path: /tmp/b485d157-d6d9-4da9-bd3a-36029fe3ed0e/cache.tzst
| [command]/usr/bin/tar --posix -cf cache.tzst --exclude cache.tzst -P -C /home/d/Downloads/numscript-wasm --files-from manifest.txt --use-compress-program zstdmt
[Release/release]   💬  ::debug::File Size: 33938120
[Release/release]   💬  ::debug::Reserving Cache
[Release/release]   💬  ::debug::Resource Url: http://192.168.0.159:42675/_apis/artifactcache/caches
[Release/release]   💬  ::debug::Saving Cache (ID: 15)
[Release/release]   💬  ::debug::Upload cache
[Release/release]   💬  ::debug::Resource Url: http://192.168.0.159:42675/_apis/artifactcache/caches/15
[Release/release]   💬  ::debug::Upload concurrency: 4
[Release/release]   💬  ::debug::Upload chunk size: 33554432
[Release/release]   💬  ::debug::Awaiting all uploads
[Release/release]   💬  ::debug::Uploading chunk of size 33554432 bytes at offset 0 with content range: bytes 0-33554431/*
[Release/release]   💬  ::debug::Uploading chunk of size 383688 bytes at offset 33554432 with content range: bytes 33554432-33938119/*
[Release/release]   💬  ::debug::Commiting cache
| Cache Size: ~32 MB (33938120 B)
[Release/release]   💬  ::debug::Resource Url: http://192.168.0.159:42675/_apis/artifactcache/caches/15
| Cache saved successfully
| Cache saved with the key: setup-go-Linux-ubuntu20-go-1.22.10-c81e5a061266eb76f60890cfd10123bd4a649b9bc5d6ee1443b04f04d4fe2b1e
[Release/release]   ✅  Success - Post Set up Go
[Release/release] ⭐ Run Post actions/cache@v3
[Release/release]   🐳  docker exec cmd=[/opt/acttoolcache/node/18.20.5/x64/bin/node /var/run/act/actions/actions-cache@v3/dist/save/index.js] user= workdir=
[Release/release]   💬  ::debug::Cache service version: v1
[Release/release]   💬  ::debug::Checking zstd --quiet --version
[Release/release]   💬  ::debug::1.4.8
[Release/release]   💬  ::debug::zstd version: 1.4.8
[Release/release]   💬  ::debug::implicitDescendants 'false'
[Release/release]   💬  ::debug::followSymbolicLinks 'true'
[Release/release]   💬  ::debug::implicitDescendants 'false'
[Release/release]   💬  ::debug::omitBrokenSymbolicLinks 'true'
[Release/release]   💬  ::debug::Search path '/tmp/.cache'
[Release/release]   💬  ::debug::Cache Paths:
[Release/release]   💬  ::debug::[]
| [warning]Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.
[Release/release]   ✅  Success - Post actions/cache@v3
[Release/release] Cleaning up container for job release
[Release/release] 🏁  Job succeeded

Changes walkthrough 📝

Relevant files
Enhancement
download-wasm.sh
Add script for downloading WASM builds                                     

scripts/download-wasm.sh

  • Added a script to download the latest or specified version of
    numscript.wasm.
  • Utilizes GitHub API to fetch the latest release version.
  • Downloads the WASM file to a specified directory.
  • +20/-0   
    Configuration changes
    .envrc
    Add Nix flake usage in environment configuration                 

    .envrc

    • Added a directive to use Nix flake for environment configuration.
    +1/-0     
    release.yml
    Update CI/CD pipeline for WASM build and release                 

    .github/workflows/release.yml

  • Updated Go version to 1.21.5 for TinyGo compatibility.
  • Added steps to install TinyGo and build WASM files.
  • Configured GitHub Actions to upload WASM artifacts to releases.
  • +27/-4   
    flake.nix
    Introduce Nix flake for development environment setup       

    flake.nix

  • Introduced a Nix flake for setting up the development environment.
  • Configures dependencies including Go and TinyGo.
  • Provides a shell hook for environment setup.
  • +35/-0   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @debora-be debora-be self-assigned this Dec 27, 2024
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The script does not handle potential errors from the curl command when fetching the latest release version. Consider adding error handling to ensure robustness.

    if [ "$VERSION" = "latest" ]; then
      VERSION=$(curl -s https://api.github.com/repos/$REPO/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
    fi
    Hardcoded TinyGo Version

    The TinyGo version is hardcoded in the workflow. Consider parameterizing this to allow easier updates in the future.

    - name: Install TinyGo
      run: |
        wget https://github.com/tinygo-org/tinygo/releases/download/v0.30.0/tinygo_0.30.0_amd64.deb
        sudo dpkg -i tinygo_0.30.0_amd64.deb

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Add error handling for the curl command to manage unsuccessful HTTP responses

    Ensure that the curl command checks for successful HTTP response codes to handle
    potential download errors gracefully.

    scripts/download-wasm.sh [18]

    -curl -L "https://github.com/$REPO/releases/download/$VERSION/numscript.wasm" -o priv/wasm/numscript.wasm
    +curl -fL "https://github.com/$REPO/releases/download/$VERSION/numscript.wasm" -o priv/wasm/numscript.wasm
    Suggestion importance[1-10]: 8

    Why: The suggestion improves the robustness of the script by ensuring that the curl command fails on unsuccessful HTTP responses, which is crucial for reliable downloads. This change directly enhances error handling in the script.

    8
    Add error handling for the GitHub release upload command to ensure successful artifact uploads

    Verify that the gh release upload command includes error handling to ensure the
    upload process is successful.

    .github/workflows/release.yml [54]

    -gh release upload ${{ github.event.release.tag_name }} build/numscript.wasm
    +gh release upload ${{ github.event.release.tag_name }} build/numscript.wasm || exit 1
    Suggestion importance[1-10]: 7

    Why: The suggestion introduces error handling for the gh release upload command, which is important for ensuring that the upload process does not silently fail. This enhances the reliability of the release workflow.

    7

    @fermuch fermuch self-requested a review December 27, 2024 14:28
    .github/workflows/release.yml Outdated Show resolved Hide resolved
    .github/workflows/release.yml Outdated Show resolved Hide resolved
    scripts/download-wasm.sh Outdated Show resolved Hide resolved
    scripts/download-wasm.sh Outdated Show resolved Hide resolved
    scripts/download-wasm.sh Outdated Show resolved Hide resolved
    flake.nix Show resolved Hide resolved
    .github/workflows/nix.yml Outdated Show resolved Hide resolved
    @fermuch
    Copy link

    fermuch commented Jan 8, 2025

    Por favor fazer rebase (ou merge) com main para pegar as novas configurações de goreleaser.

    .github/workflows/release.yml Show resolved Hide resolved
    .github/workflows/release.yml Outdated Show resolved Hide resolved
    flake.nix Outdated Show resolved Hide resolved
    internal/parser/antlr/numscript_base_listener.go Outdated Show resolved Hide resolved
    internal/parser/antlr/numscript_lexer.go Outdated Show resolved Hide resolved
    internal/parser/antlr/numscript_listener.go Outdated Show resolved Hide resolved
    internal/parser/antlr/numscript_parser.go Outdated Show resolved Hide resolved
    internal/parser/parser.go Outdated Show resolved Hide resolved
    @Vinocis Vinocis requested review from Vinocis and fermuch January 23, 2025 15:59
    Copy link

    @fermuch fermuch left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    LGTM!

    @fermuch fermuch merged commit 51d6a43 into main Jan 23, 2025
    4 checks passed
    @fermuch fermuch deleted the feat/ci-cd-for-numscript#86b37qfxt branch January 23, 2025 17:23
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants