From dbcafbde17113738dc4f3497d9cec6ad0cfdef5b Mon Sep 17 00:00:00 2001 From: Laith Bahodi Date: Fri, 6 Dec 2024 11:28:29 -0500 Subject: [PATCH 1/4] ci: add ability to upload wasm artefacts based on release hash --- .github/workflows/release-hash.yaml | 55 ++++++++++++++++++++ .github/workflows/reusable-build-upload.yaml | 7 +++ 2 files changed, 62 insertions(+) create mode 100644 .github/workflows/release-hash.yaml diff --git a/.github/workflows/release-hash.yaml b/.github/workflows/release-hash.yaml new file mode 100644 index 00000000..b555cb49 --- /dev/null +++ b/.github/workflows/release-hash.yaml @@ -0,0 +1,55 @@ +# takes the latest commit hash on main and uploads the artefacts to CF storage +name: Release +on: + workflow_dispatch: + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +jobs: + define-matrix: + runs-on: blacksmith-2vcpu-ubuntu-2204 + + outputs: + releases: ${{ steps.prepare-matrix.outputs.releases }} + + steps: + - name: Prepare JSON output to be a matrix GHA format + id: prepare-matrix + run: | + # -J for json, -d for directories, -L 1 for depth of 1 + export NAMES=$(tree -J -d -L 1 contracts | jq -c '.[0].contents | map(.name)') + echo "releases=$NAMES" >> $GITHUB_OUTPUT + + # Publishes a release in case the release isn't published + build-and-upload: + name: Publish releases + + runs-on: blacksmith-2vcpu-ubuntu-2204 + needs: define-matrix + + strategy: + matrix: + releases: ${{ fromJson(needs.define-matrix.outputs.releases) }} + + uses: ./.github/workflows/reusable-build-upload.yaml + permissions: + id-token: write + contents: read + with: + package-name: "${{ matrix.releases.package_name }}" + package-version: "${{ github.sha }}" + + # CF Bucket related variables + cf-bucket-name: "${{ vars.CF_BUCKET_NAME }}" + + # The root key to be used for accessing the configs. (ex: `test-root-key` puts releases in `test-root-key/*`) + cf-config-bucket-root-key: "${{ vars.CF_BUCKET_ROOT_KEY }}" + + # we just want to upload to CF, do not run a github release + github-release: "false" + + secrets: + github-token: "${{ secrets.PAT_TOKEN }}" + cf-endpoint-url: "${{ secrets.CF_ENDPOINT_URL }}" + cf-bucket-access-key-id: ${{ secrets.CF_BUCKET_ACCESS_KEY_ID }} + cf-bucket-secret-access-key: ${{ secrets.CF_BUCKET_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/reusable-build-upload.yaml b/.github/workflows/reusable-build-upload.yaml index bbc6654d..eb9d5606 100644 --- a/.github/workflows/reusable-build-upload.yaml +++ b/.github/workflows/reusable-build-upload.yaml @@ -33,6 +33,12 @@ on: required: true type: string + github-release: + description: "Whether to upload the build as a github release" + required: false + default: "true" + type: boolean + secrets: github-token: description: "The github token to use to do the tag updates" @@ -176,6 +182,7 @@ jobs: # https://github.com/orgs/community/discussions/26263#discussioncomment-3251069 - name: Update the GitHub Release uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8 + if: ${{ inputs.github-release == 'true' }} with: tag_name: ${{ inputs.package-git-tag }} # This uses the tag from the push files: | From 49c07dd2b6b7a32a20a9bc755340e3b7a64bc3ab Mon Sep 17 00:00:00 2001 From: ahramy Date: Thu, 30 Jan 2025 16:01:37 -0800 Subject: [PATCH 2/4] updated --- .../{release-hash.yaml => pre-release.yaml} | 37 ++++++++++++++----- .github/workflows/reusable-build-upload.yaml | 10 ++--- 2 files changed, 32 insertions(+), 15 deletions(-) rename .github/workflows/{release-hash.yaml => pre-release.yaml} (51%) diff --git a/.github/workflows/release-hash.yaml b/.github/workflows/pre-release.yaml similarity index 51% rename from .github/workflows/release-hash.yaml rename to .github/workflows/pre-release.yaml index b555cb49..a011bd15 100644 --- a/.github/workflows/release-hash.yaml +++ b/.github/workflows/pre-release.yaml @@ -1,5 +1,5 @@ # takes the latest commit hash on main and uploads the artefacts to CF storage -name: Release +name: Pre-release on: workflow_dispatch: @@ -13,31 +13,48 @@ jobs: releases: ${{ steps.prepare-matrix.outputs.releases }} steps: - - name: Prepare JSON output to be a matrix GHA format + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Get latest commit hash + id: get-commit-hash + run: echo "commit_hash=$(git rev-parse HEAD)" >> "$GITHUB_ENV" + + - name: Prepare JSON output for matrix id: prepare-matrix run: | - # -J for json, -d for directories, -L 1 for depth of 1 - export NAMES=$(tree -J -d -L 1 contracts | jq -c '.[0].contents | map(.name)') - echo "releases=$NAMES" >> $GITHUB_OUTPUT + # Extract package names from the 'contracts' directory and format properly + RELEASES_JSON=$(find contracts -maxdepth 1 -mindepth 1 -type d | sed 's|contracts/||' | jq -R . | jq -s --arg commit "${{ env.commit_hash }}" 'map({package_name: ., version: $commit, tag: .})') + + # Debugging output + echo "Generated releases JSON: $RELEASES_JSON" + + # Properly set output with correct JSON format + echo "releases=$(echo "$RELEASES_JSON" | jq -c)" >> "$GITHUB_OUTPUT" # Publishes a release in case the release isn't published build-and-upload: - name: Publish releases - - runs-on: blacksmith-2vcpu-ubuntu-2204 + name: Build artifacts for ${{ matrix.releases.package_name }}-${{ matrix.releases.version }} needs: define-matrix + # Once a release is done for a package, we iterate on each of these packages and build its corresponding artifacts and upload them strategy: matrix: releases: ${{ fromJson(needs.define-matrix.outputs.releases) }} uses: ./.github/workflows/reusable-build-upload.yaml + permissions: id-token: write contents: read + with: package-name: "${{ matrix.releases.package_name }}" - package-version: "${{ github.sha }}" + package-version: "${{ matrix.releases.version }}" + package-git-tag: "${{ matrix.releases.tag }}" # CF Bucket related variables cf-bucket-name: "${{ vars.CF_BUCKET_NAME }}" @@ -46,7 +63,7 @@ jobs: cf-config-bucket-root-key: "${{ vars.CF_BUCKET_ROOT_KEY }}" # we just want to upload to CF, do not run a github release - github-release: "false" + github-release: false secrets: github-token: "${{ secrets.PAT_TOKEN }}" diff --git a/.github/workflows/reusable-build-upload.yaml b/.github/workflows/reusable-build-upload.yaml index 55bce251..191ba939 100644 --- a/.github/workflows/reusable-build-upload.yaml +++ b/.github/workflows/reusable-build-upload.yaml @@ -36,7 +36,7 @@ on: github-release: description: "Whether to upload the build as a github release" required: false - default: "true" + default: true type: boolean secrets: @@ -69,9 +69,9 @@ jobs: toolchain: 1.81.0 targets: wasm32-unknown-unknown - - name: Build artifacts for ${{ inputs.package-name }}-v${{ inputs.package-version }} + - name: Build artifacts for ${{ inputs.package-name }} run: | - echo "Building wasm for '${{ inputs.package-name }}-v${{ inputs.package-version }}'"; + echo "Building wasm for '${{ inputs.package-name }}'"; cargo install --locked stellar-cli --version 22.2.0 --features opt cargo wasm -p ${{ inputs.package-name }} stellar contract build @@ -81,7 +81,7 @@ jobs: - name: Prepare cross-steps variables run: | export PACKAGE_NAME='${{ inputs.package-name }}' - export PACKAGE_VERSION='v${{ inputs.package-version }}' + export PACKAGE_VERSION=${{ inputs.github-release && format('v{0}', inputs.package-version) || inputs.package-version }} export BASE_ARTIFACTS_DIR="./target/wasm32-unknown-unknown/release" export ARTIFACT_NAME="axelar-cgp-stellar-wasm-${PACKAGE_NAME}-${PACKAGE_VERSION}" @@ -182,7 +182,7 @@ jobs: # https://github.com/orgs/community/discussions/26263#discussioncomment-3251069 - name: Update the GitHub Release uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8 - if: ${{ inputs.github-release == 'true' }} + if: inputs.github-release with: tag_name: ${{ inputs.package-git-tag }} # This uses the tag from the push files: | From 62b2b58b452cd2347af15dea7b70084a68af0a2c Mon Sep 17 00:00:00 2001 From: ahramy Date: Thu, 30 Jan 2025 16:03:48 -0800 Subject: [PATCH 3/4] Update pre-release.yaml --- .github/workflows/pre-release.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml index a011bd15..7df3f65f 100644 --- a/.github/workflows/pre-release.yaml +++ b/.github/workflows/pre-release.yaml @@ -26,13 +26,8 @@ jobs: - name: Prepare JSON output for matrix id: prepare-matrix run: | - # Extract package names from the 'contracts' directory and format properly RELEASES_JSON=$(find contracts -maxdepth 1 -mindepth 1 -type d | sed 's|contracts/||' | jq -R . | jq -s --arg commit "${{ env.commit_hash }}" 'map({package_name: ., version: $commit, tag: .})') - - # Debugging output echo "Generated releases JSON: $RELEASES_JSON" - - # Properly set output with correct JSON format echo "releases=$(echo "$RELEASES_JSON" | jq -c)" >> "$GITHUB_OUTPUT" # Publishes a release in case the release isn't published From 50db71825ff5782893c73b8dcdd344204d85b11a Mon Sep 17 00:00:00 2001 From: ahramy Date: Thu, 30 Jan 2025 16:04:49 -0800 Subject: [PATCH 4/4] Update pre-release.yaml --- .github/workflows/pre-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml index 7df3f65f..98620c45 100644 --- a/.github/workflows/pre-release.yaml +++ b/.github/workflows/pre-release.yaml @@ -57,7 +57,7 @@ jobs: # The root key to be used for accessing the configs. (ex: `test-root-key` puts releases in `test-root-key/*`) cf-config-bucket-root-key: "${{ vars.CF_BUCKET_ROOT_KEY }}" - # we just want to upload to CF, do not run a github release + # We only want to upload to CF, do not run a github release github-release: false secrets: