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

ci: add ability to upload wasm artefacts based on release hash #100

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# takes the latest commit hash on main and uploads the artefacts to CF storage
ahramy marked this conversation as resolved.
Show resolved Hide resolved
name: Pre-release
ahramy marked this conversation as resolved.
Show resolved Hide resolved
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: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y jq
ahramy marked this conversation as resolved.
Show resolved Hide resolved

- 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: |
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: .})')
echo "Generated releases JSON: $RELEASES_JSON"
echo "releases=$(echo "$RELEASES_JSON" | jq -c)" >> "$GITHUB_OUTPUT"

# Publishes a release in case the release isn't published
build-and-upload:
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) }}
Copy link
Member

Choose a reason for hiding this comment

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

Very inefficient, we're rebuilding each contract although they're all on the same commit. Separate the build and cloudflare upload into their own reusable workflows, so the build can be run once, and cloudflare push can be done for each contract


uses: ./.github/workflows/reusable-build-upload.yaml

permissions:
id-token: write
contents: read

with:
package-name: "${{ matrix.releases.package_name }}"
package-version: "${{ matrix.releases.version }}"
package-git-tag: "${{ matrix.releases.tag }}"

# 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 only 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 }}
13 changes: 10 additions & 3 deletions .github/workflows/reusable-build-upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -63,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
Expand All @@ -75,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}"
Expand Down Expand Up @@ -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
with:
tag_name: ${{ inputs.package-git-tag }} # This uses the tag from the push
files: |
Expand Down
Loading