-
Notifications
You must be signed in to change notification settings - Fork 3
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: upload contracts to CF R2 from main #100
Changes from 12 commits
dbcafbd
3a6fd1c
30dfc37
49c07dd
cc6a1b5
62b2b58
8700b9c
50db718
26d65db
6c9d0a2
a46fa3d
98d3fa8
9301582
3d6844b
8240087
a1e8954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Workflow to fetch the latest commit hash on the main branch and upload artifacts to CF storage. | ||
name: Build and upload from main | ||
on: | ||
workflow_dispatch: | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
define-matrix: | ||
name: Define Matrix | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
runs-on: blacksmith-2vcpu-ubuntu-2204 | ||
outputs: | ||
releases: ${{ steps.prepare-matrix.outputs.releases }} | ||
commit_hash: ${{ steps.get-commit-hash.outputs.hash }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install dependencies | ||
run: sudo apt-get install -y jq | ||
|
||
- name: Get latest commit hash | ||
id: get-commit-hash | ||
run: echo "hash=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" | ||
|
||
- 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 "${{ steps.get-commit-hash.outputs.hash }}" 'map({ | ||
package_name: ., | ||
version: $commit, | ||
package_git_tag: "\(.)_\($commit)" | ||
})') | ||
Comment on lines
+30
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is overkill, the commit is the same now, we just need to list all contract names There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also consider the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we aren't releasing to crates.io here. Take a look at how the |
||
echo "releases=$(echo "$RELEASES_JSON" | jq -c)" >> "$GITHUB_OUTPUT" | ||
|
||
build: | ||
needs: define-matrix | ||
uses: ./.github/workflows/reusable-build.yaml | ||
with: | ||
commit-hash: ${{ needs.define-matrix.outputs.commit_hash }} | ||
|
||
upload: | ||
needs: [define-matrix, build] | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
strategy: | ||
matrix: | ||
releases: ${{ fromJson(needs.define-matrix.outputs.releases) }} | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
uses: ./.github/workflows/reusable-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.package_git_tag }} | ||
artifact-name: ${{ needs.build.outputs.artifact-name }} | ||
cf-bucket-name: ${{ vars.CF_BUCKET_NAME }} | ||
cf-config-bucket-root-key: ${{ vars.CF_BUCKET_ROOT_KEY }} | ||
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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,14 @@ on: | |
pull_request: | ||
branches: | ||
- main | ||
- 'releases/**' | ||
- "releases/**" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just |
||
types: [closed] | ||
|
||
workflow_dispatch: | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
|
||
# Publishes a release in case the release isn't published | ||
publish-release: | ||
name: Publish releases | ||
|
@@ -24,10 +23,11 @@ jobs: | |
((github.event.pull_request.merged == true) && | ||
contains(github.event.pull_request.labels.*.name, 'release')) | ||
|
||
runs-on: blacksmith-8vcpu-ubuntu-2204 | ||
runs-on: blacksmith-2vcpu-ubuntu-2204 | ||
|
||
outputs: | ||
releases: ${{ steps.prepare-matrix.outputs.releases }} | ||
commit_hash: ${{ steps.get-commit-hash.outputs.hash }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
|
@@ -39,6 +39,10 @@ jobs: | |
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
|
||
- name: Get commit hash | ||
id: get-commit-hash | ||
run: echo "hash=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" | ||
|
||
# Creates git tags and publishes the crates of the new releases | ||
- name: Publish release | ||
id: publish-release | ||
|
@@ -56,35 +60,32 @@ jobs: | |
run: | | ||
echo "releases=$(echo '${{ steps.publish-release.outputs.releases }}' | jq -c '.')" >> $GITHUB_OUTPUT | ||
|
||
# Creates other artifacts needed (`wasm` files) | ||
build-and-upload: | ||
name: Build artifacts for ${{ matrix.releases.package_name }}-v${{ matrix.releases.version }} | ||
build: | ||
needs: publish-release | ||
uses: ./.github/workflows/reusable-build.yaml | ||
with: | ||
commit-hash: ${{ needs.publish-release.outputs.commit_hash }} | ||
Comment on lines
+64
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? This is creating a build on the current commit hash instead of using the release tags created for every contract by release-plz. So, the built wasm files won't correspond to the release tag? The release matrix needs to be applied for both build and upload, unless all release tags are the same commit |
||
|
||
# Once a release is done for a package, we iterate on each of these packages and build its corresponding artifacts and upload them | ||
upload: | ||
needs: [publish-release, build] | ||
strategy: | ||
matrix: | ||
releases: ${{ fromJson(needs.publish-release.outputs.releases) }} | ||
|
||
uses: ./.github/workflows/reusable-build-upload.yaml | ||
|
||
uses: ./.github/workflows/reusable-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 }}" | ||
|
||
package-name: ${{ matrix.releases.package_name }} | ||
package-version: ${{ matrix.releases.version }} | ||
package-git-tag: ${{ matrix.releases.tag }} | ||
artifact-name: ${{ needs.build.outputs.artifact-name }} | ||
cf-bucket-name: ${{ vars.CF_BUCKET_NAME }} | ||
cf-config-bucket-root-key: ${{ vars.CF_BUCKET_ROOT_KEY }} | ||
github-release: true | ||
secrets: | ||
github-token: "${{ secrets.PAT_TOKEN }}" | ||
cf-endpoint-url: "${{ secrets.CF_ENDPOINT_URL }}" | ||
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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: "Build Contracts" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
commit-hash: | ||
description: "The commit hash to build from" | ||
type: string | ||
required: true | ||
outputs: | ||
artifact-name: | ||
description: "Name of the uploaded artifact containing all builds" | ||
value: ${{ jobs.build.outputs.artifact-name }} | ||
|
||
jobs: | ||
build: | ||
runs-on: blacksmith-8vcpu-ubuntu-2204 | ||
outputs: | ||
artifact-name: ${{ steps.set-artifact-name.outputs.name }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Checkout specific commit | ||
run: git checkout ${{ inputs.commit-hash }} | ||
|
||
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: 1.76.0 | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
targets: wasm32-unknown-unknown | ||
|
||
- name: Set artifact name | ||
id: set-artifact-name | ||
run: | | ||
echo "name=wasm-builds-${{ inputs.commit-hash }}" >> $GITHUB_OUTPUT | ||
|
||
- name: Build all contracts | ||
run: | | ||
# 21.1.1 is the latest rust 1.76.0 compatible version, the version after is 21.2.0 which is compatible with 1.79.0 (different than the workspace's version) | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cargo install --locked soroban-cli --version 21.1.1 --features opt | ||
|
||
# Build all contracts | ||
cargo wasm | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
./optimize.sh | ||
|
||
# Create directory for storing optimized WASM files | ||
mkdir -p wasm-builds | ||
|
||
# Process in the release directory | ||
cd target/wasm32-unknown-unknown/release | ||
|
||
# Remove unoptimized files and rename optimized ones | ||
# This ensures we only keep the optimized versions | ||
find . -type f -name "*.wasm" ! -name "*.optimized.wasm" -maxdepth 1 -delete | ||
find . -name "*.optimized.wasm" -maxdepth 1 -exec sh -c 'mv "$0" "${0%.optimized.wasm}.wasm"' {} \; | ||
|
||
# Move all optimized WASM files to the builds directory | ||
mv *.wasm ../../../wasm-builds/ | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
ahramy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with: | ||
name: ${{ steps.set-artifact-name.outputs.name }} | ||
path: wasm-builds | ||
retention-days: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`# Build Stellar contracts on every commit to main and upload the wasm code to Cloudflare R2