|
| 1 | +name: Build and Release Crowdfund Contract |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + release_name: |
| 10 | + description: "Release Version (e.g. v0.0.0)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + id-token: write |
| 16 | + contents: write |
| 17 | + attestations: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + release: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Install Rust |
| 26 | + run: | |
| 27 | + rustup update |
| 28 | + rustup target add wasm32v1-none |
| 29 | +
|
| 30 | + - name: Set up env vars |
| 31 | + run: | |
| 32 | + echo "WASM_DIR=target/wasm32v1-none/release" >> $GITHUB_ENV |
| 33 | + if [ -n "${{ github.event.inputs.release_name }}" ]; then |
| 34 | + echo "TAG_NAME=${{ github.event.inputs.release_name }}" >> $GITHUB_ENV |
| 35 | + else |
| 36 | + echo "TAG_NAME=${{ github.ref_name }}" >> $GITHUB_ENV |
| 37 | + fi |
| 38 | +
|
| 39 | + - name: Set up Stellar CLI |
| 40 | + uses: stellar/stellar-cli@v22.8.1 |
| 41 | + with: |
| 42 | + version: 22.8.1 |
| 43 | + |
| 44 | + - name: Build all contracts |
| 45 | + run: | |
| 46 | + stellar contract build \ |
| 47 | + --meta home_domain=boundless.fi \ |
| 48 | + --meta source_repo=github:${{ github.repository }} |
| 49 | + |
| 50 | + # Optimize all generated wasms |
| 51 | + for wasm in ${{ env.WASM_DIR }}/*.wasm; do |
| 52 | + # Skip already optimized ones if any |
| 53 | + if [[ "$wasm" == *".optimized.wasm" ]]; then continue; fi |
| 54 | + |
| 55 | + echo "Optimizing $wasm..." |
| 56 | + stellar contract optimize --wasm "$wasm" |
| 57 | + |
| 58 | + # Replace original with optimized |
| 59 | + optimized="${wasm%.wasm}.optimized.wasm" |
| 60 | + if [ -f "$optimized" ]; then |
| 61 | + mv "$optimized" "$wasm" |
| 62 | + fi |
| 63 | + done |
| 64 | +
|
| 65 | + - name: Upload to Artifacts |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: boundless-contracts |
| 69 | + path: ${{ env.WASM_DIR }}/*.wasm |
| 70 | + |
| 71 | + - name: Build Attestations |
| 72 | + uses: actions/attest-build-provenance@v1 |
| 73 | + with: |
| 74 | + subject-path: "${{ env.WASM_DIR }}/*.wasm" |
| 75 | + |
| 76 | + - name: Make a new Release |
| 77 | + id: release |
| 78 | + uses: actions/github-script@v7 |
| 79 | + with: |
| 80 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + script: | |
| 82 | + const response = await github.rest.repos.createRelease({ |
| 83 | + owner: context.repo.owner, |
| 84 | + repo: context.repo.repo, |
| 85 | + tag_name: '${{ env.TAG_NAME }}', |
| 86 | + target_commitish: '${{ github.sha }}', |
| 87 | + make_latest: 'true', |
| 88 | + name: '${{ env.TAG_NAME }}' |
| 89 | + }); |
| 90 | + const { data } = response; |
| 91 | + core.setOutput('release_id', data.id); |
| 92 | +
|
| 93 | + - name: Upload to Release |
| 94 | + uses: actions/github-script@v7 |
| 95 | + with: |
| 96 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + script: | |
| 98 | + const fs = require('fs'); |
| 99 | + const path = require('path'); |
| 100 | + const wasmDir = '${{ env.WASM_DIR }}'; |
| 101 | + const files = fs.readdirSync(wasmDir).filter(f => f.endsWith('.wasm')); |
| 102 | + |
| 103 | + for (const file of files) { |
| 104 | + console.log(`Uploading ${file}...`); |
| 105 | + await github.rest.repos.uploadReleaseAsset({ |
| 106 | + owner: context.repo.owner, |
| 107 | + repo: context.repo.repo, |
| 108 | + release_id: '${{ steps.release.outputs.release_id }}', |
| 109 | + name: file, |
| 110 | + data: fs.readFileSync(path.join(wasmDir, file)), |
| 111 | + }); |
| 112 | + } |
0 commit comments