|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_tag: |
| 7 | + description: "Release tag (e.g., v1.0.0)" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + release_notes: |
| 11 | + description: "Release notes (optional, will use commit messages if not provided)" |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +env: |
| 16 | + CARGO_TERM_COLOR: always |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.event.inputs.release_tag }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-binaries: |
| 24 | + name: Build Binaries |
| 25 | + runs-on: ${{ matrix.os }} |
| 26 | + strategy: |
| 27 | + matrix: |
| 28 | + os: |
| 29 | + - ubuntu-latest |
| 30 | + - macos-latest |
| 31 | + include: |
| 32 | + - os: ubuntu-latest |
| 33 | + target: x86_64-unknown-linux-gnu |
| 34 | + bin_name: wasic |
| 35 | + asset_name: wasic-${{ github.event.inputs.release_tag }}-x86_64-unknown-linux-gnu.tar.gz |
| 36 | + - os: macos-latest |
| 37 | + target: aarch64-apple-darwin |
| 38 | + bin_name: wasic |
| 39 | + asset_name: wasic-${{ github.event.inputs.release_tag }}-aarch64-apple-darwin.tar.gz |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout repository |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Setup Rust |
| 46 | + uses: dtolnay/rust-toolchain@stable |
| 47 | + with: |
| 48 | + targets: ${{ matrix.target }} |
| 49 | + |
| 50 | + - name: Install just |
| 51 | + uses: extractions/setup-just@v2 |
| 52 | + |
| 53 | + - name: Cache cargo registry |
| 54 | + uses: actions/cache@v4 |
| 55 | + with: |
| 56 | + path: | |
| 57 | + ~/.cargo/registry |
| 58 | + ~/.cargo/git |
| 59 | + target |
| 60 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 61 | + restore-keys: | |
| 62 | + ${{ runner.os }}-cargo- |
| 63 | +
|
| 64 | + - name: Install tools |
| 65 | + run: | |
| 66 | + just install-tools |
| 67 | +
|
| 68 | + - name: Build and validate |
| 69 | + run: | |
| 70 | + just lint |
| 71 | +
|
| 72 | + - name: Build binary |
| 73 | + run: | |
| 74 | + cargo build --release --target ${{ matrix.target }} |
| 75 | +
|
| 76 | + - name: Package binary (Linux/macOS) |
| 77 | + if: matrix.os != 'windows-latest' |
| 78 | + run: | |
| 79 | + mkdir -p artifacts |
| 80 | + cp "target/${{ matrix.target }}/release/${{ matrix.bin_name }}" artifacts/ |
| 81 | + cd artifacts |
| 82 | + tar -czf "${{ matrix.asset_name }}" "${{ matrix.bin_name }}" |
| 83 | +
|
| 84 | + - name: Package binary (Windows) |
| 85 | + if: matrix.os == 'windows-latest' |
| 86 | + run: | |
| 87 | + mkdir -p artifacts |
| 88 | + cp "target/${{ matrix.target }}/release/${{ matrix.bin_name }}" artifacts/ |
| 89 | + cd artifacts |
| 90 | + 7z a -tzip "${{ matrix.asset_name }}" "${{ matrix.bin_name }}" |
| 91 | +
|
| 92 | + - name: Upload artifacts |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + with: |
| 95 | + name: ${{ matrix.asset_name }} |
| 96 | + path: artifacts/${{ matrix.asset_name }} |
| 97 | + |
| 98 | + create-release: |
| 99 | + name: Create GitHub Release |
| 100 | + needs: build-binaries |
| 101 | + runs-on: ubuntu-latest |
| 102 | + permissions: |
| 103 | + contents: write |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: Download all artifacts |
| 107 | + uses: actions/download-artifact@v4 |
| 108 | + with: |
| 109 | + path: artifacts/ |
| 110 | + |
| 111 | + - name: Generate Release Notes |
| 112 | + id: generate_release_notes |
| 113 | + uses: actions/github-script@v7 |
| 114 | + with: |
| 115 | + script: | |
| 116 | + const { owner, repo } = context.repo; |
| 117 | + const tag = context.ref.replace('refs/tags/', ''); |
| 118 | + const releaseName = `Release ${tag}`; |
| 119 | +
|
| 120 | + // Try to get release notes from the tag's annotation |
| 121 | + try { |
| 122 | + const tagData = await github.rest.git.getTag({ |
| 123 | + owner, |
| 124 | + repo, |
| 125 | + tag_sha: context.sha, |
| 126 | + }); |
| 127 | + if (tagData.data.message) { |
| 128 | + core.setOutput('notes', tagData.data.message); |
| 129 | + return; |
| 130 | + } |
| 131 | + } catch (e) { |
| 132 | + console.log('No tag annotation found, falling back to commit messages.'); |
| 133 | + } |
| 134 | +
|
| 135 | + // Fallback to commit messages since the last tag |
| 136 | + const { data: tags } = await github.rest.repos.listTags({ |
| 137 | + owner, |
| 138 | + repo, |
| 139 | + per_page: 2, |
| 140 | + }); |
| 141 | +
|
| 142 | + let baseSha; |
| 143 | + if (tags.length > 1 && tags[1].name !== tag) { |
| 144 | + baseSha = tags[1].commit.sha; |
| 145 | + } else { |
| 146 | + // If no previous tag, get the first commit |
| 147 | + const { data: commits } = await github.rest.repos.listCommits({ |
| 148 | + owner, |
| 149 | + repo, |
| 150 | + per_page: 1, |
| 151 | + }); |
| 152 | + baseSha = commits[0].sha; |
| 153 | + } |
| 154 | +
|
| 155 | + const { data: compare } = await github.rest.repos.compareCommits({ |
| 156 | + owner, |
| 157 | + repo, |
| 158 | + base: baseSha, |
| 159 | + head: context.sha, |
| 160 | + }); |
| 161 | +
|
| 162 | + const notes = compare.commits.map(commit => { |
| 163 | + return `- ${commit.commit.message.split('\\n')[0]} (${commit.sha.substring(0, 7)})`; |
| 164 | + }).join('\\n'); |
| 165 | +
|
| 166 | + core.setOutput('notes', `## Changes\\n\\n${notes}`); |
| 167 | +
|
| 168 | + - name: Create Release |
| 169 | + uses: softprops/action-gh-release@v2 |
| 170 | + with: |
| 171 | + tag_name: ${{ github.event.inputs.release_tag }} |
| 172 | + name: Release ${{ github.event.inputs.release_tag }} |
| 173 | + body: ${{ github.event.inputs.release_notes || steps.generate_release_notes.outputs.notes }} |
| 174 | + files: | |
| 175 | + artifacts/**/*.tar.gz |
| 176 | + artifacts/**/*.zip |
| 177 | + env: |
| 178 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments