|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to release (e.g., 1.0.0)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +env: |
| 12 | + DEBUG: napi:* |
| 13 | + APP_NAME: atlas-local |
| 14 | + MACOSX_DEPLOYMENT_TARGET: '10.13' |
| 15 | + |
| 16 | +jobs: |
| 17 | + update-version: |
| 18 | + name: Update Version |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + version: ${{ steps.version.outputs.version }} |
| 22 | + steps: |
| 23 | + - name: Set Apix Bot token |
| 24 | + id: app-token |
| 25 | + uses: mongodb/apix-action/token@6c3fde402c21942fa46cde003f190c2b23c59530 |
| 26 | + with: |
| 27 | + app-id: ${{ secrets.APIXBOT_APP_ID }} |
| 28 | + private-key: ${{ secrets.APIXBOT_APP_PEM }} |
| 29 | + - uses: actions/checkout@v5 |
| 30 | + with: |
| 31 | + token: ${{ steps.app-token.outputs.token }} |
| 32 | + fetch-depth: 0 |
| 33 | + - name: Setup node |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: 22 |
| 37 | + cache: yarn |
| 38 | + - name: Install Rust toolchain |
| 39 | + uses: dtolnay/rust-toolchain@stable |
| 40 | + with: |
| 41 | + toolchain: stable |
| 42 | + targets: x86_64-unknown-linux-gnu |
| 43 | + - name: Install dependencies |
| 44 | + run: yarn install |
| 45 | + - name: Install cargo tools for license verification |
| 46 | + run: | |
| 47 | + cargo install --locked --version 0.8.2 cargo-about |
| 48 | + - name: Update package.json version |
| 49 | + run: | |
| 50 | + npm version ${{ github.event.inputs.version }} --no-git-tag-version |
| 51 | + - name: Update Cargo.toml version |
| 52 | + run: | |
| 53 | + sed -i 's/^version = ".*"/version = "${{ github.event.inputs.version }}"/' Cargo.toml |
| 54 | + - name: Update third-party licenses |
| 55 | + run: | |
| 56 | + cargo about generate about.hbs > LICENSE-3RD-PARTY.txt |
| 57 | + - name: Generate changelog |
| 58 | + uses: orhun/git-cliff-action@v4 |
| 59 | + with: |
| 60 | + config: cliff.toml |
| 61 | + args: --verbose |
| 62 | + env: |
| 63 | + OUTPUT: CHANGELOG.md |
| 64 | + GITHUB_REPO: ${{ github.repository }} |
| 65 | + - name: Build to update generated files |
| 66 | + run: yarn build --target x86_64-unknown-linux-gnu --use-napi-cross |
| 67 | + - name: Commit version changes |
| 68 | + run: | |
| 69 | + git config --global user.name "${{ steps.app-token.outputs.user-name }}" |
| 70 | + git config --global user.email "${{ steps.app-token.outputs.user-email }}" |
| 71 | + git add package.json Cargo.toml index.js index.d.ts CHANGELOG.md LICENSE-3RD-PARTY.txt |
| 72 | + git commit -m "${{ github.event.inputs.version }}" |
| 73 | + git push |
| 74 | + - name: Set version output |
| 75 | + id: version |
| 76 | + run: echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT |
| 77 | + |
| 78 | + build: |
| 79 | + name: Build Release |
| 80 | + needs: update-version |
| 81 | + strategy: |
| 82 | + fail-fast: false |
| 83 | + matrix: |
| 84 | + settings: |
| 85 | + - host: macos-latest |
| 86 | + target: x86_64-apple-darwin |
| 87 | + build: yarn build --target x86_64-apple-darwin |
| 88 | + - host: windows-latest |
| 89 | + build: yarn build --target x86_64-pc-windows-msvc |
| 90 | + target: x86_64-pc-windows-msvc |
| 91 | + - host: ubuntu-latest |
| 92 | + target: x86_64-unknown-linux-gnu |
| 93 | + build: yarn build --target x86_64-unknown-linux-gnu --use-napi-cross |
| 94 | + - host: macos-latest |
| 95 | + target: aarch64-apple-darwin |
| 96 | + build: yarn build --target aarch64-apple-darwin |
| 97 | + - host: ubuntu-latest |
| 98 | + target: aarch64-unknown-linux-gnu |
| 99 | + build: yarn build --target aarch64-unknown-linux-gnu --use-napi-cross |
| 100 | + runs-on: ${{ matrix.settings.host }} |
| 101 | + steps: |
| 102 | + - uses: actions/checkout@v5 |
| 103 | + with: |
| 104 | + ref: main |
| 105 | + - name: Setup node |
| 106 | + uses: actions/setup-node@v4 |
| 107 | + with: |
| 108 | + node-version: 22 |
| 109 | + cache: yarn |
| 110 | + - name: Install Rust toolchain |
| 111 | + uses: dtolnay/rust-toolchain@stable |
| 112 | + with: |
| 113 | + toolchain: stable |
| 114 | + targets: ${{ matrix.settings.target }} |
| 115 | + - name: Cache cargo |
| 116 | + uses: actions/cache@v4 |
| 117 | + with: |
| 118 | + path: | |
| 119 | + ~/.cargo/registry/index/ |
| 120 | + ~/.cargo/registry/cache/ |
| 121 | + ~/.cargo/git/db/ |
| 122 | + ~/.napi-rs |
| 123 | + .cargo-cache |
| 124 | + target/ |
| 125 | + key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }} |
| 126 | + - uses: mlugg/setup-zig@v2 |
| 127 | + if: ${{ contains(matrix.settings.target, 'musl') }} |
| 128 | + with: |
| 129 | + version: 0.14.1 |
| 130 | + - name: Install cargo-zigbuild |
| 131 | + uses: taiki-e/install-action@v2 |
| 132 | + if: ${{ contains(matrix.settings.target, 'musl') }} |
| 133 | + env: |
| 134 | + GITHUB_TOKEN: ${{ github.token }} |
| 135 | + with: |
| 136 | + tool: cargo-zigbuild |
| 137 | + - name: Setup toolchain |
| 138 | + run: ${{ matrix.settings.setup }} |
| 139 | + if: ${{ matrix.settings.setup }} |
| 140 | + shell: bash |
| 141 | + - name: Install dependencies |
| 142 | + run: yarn install |
| 143 | + - name: Build |
| 144 | + run: ${{ matrix.settings.build }} |
| 145 | + shell: bash |
| 146 | + - name: Upload artifact |
| 147 | + uses: actions/upload-artifact@v4 |
| 148 | + with: |
| 149 | + name: bindings-${{ matrix.settings.target }} |
| 150 | + path: | |
| 151 | + ${{ env.APP_NAME }}.*.node |
| 152 | + ${{ env.APP_NAME }}.*.wasm |
| 153 | + if-no-files-found: error |
| 154 | + |
| 155 | + publish: |
| 156 | + name: Publish Release |
| 157 | + runs-on: ubuntu-latest |
| 158 | + permissions: |
| 159 | + contents: write |
| 160 | + id-token: write |
| 161 | + needs: [update-version, build] |
| 162 | + steps: |
| 163 | + - uses: actions/checkout@v5 |
| 164 | + with: |
| 165 | + ref: main |
| 166 | + - name: Setup node |
| 167 | + uses: actions/setup-node@v4 |
| 168 | + with: |
| 169 | + node-version: 22 |
| 170 | + cache: yarn |
| 171 | + - name: Install dependencies |
| 172 | + run: yarn install |
| 173 | + - name: Create npm dirs |
| 174 | + run: yarn napi create-npm-dirs |
| 175 | + - name: Download all artifacts |
| 176 | + uses: actions/download-artifact@v5 |
| 177 | + with: |
| 178 | + path: artifacts |
| 179 | + - name: Move artifacts |
| 180 | + run: yarn artifacts |
| 181 | + - name: List packages |
| 182 | + run: ls -R ./npm |
| 183 | + shell: bash |
| 184 | + - name: Create GitHub Release |
| 185 | + uses: softprops/action-gh-release@v2 |
| 186 | + with: |
| 187 | + tag_name: v${{ needs.update-version.outputs.version }} |
| 188 | + name: Release v${{ needs.update-version.outputs.version }} |
| 189 | + files: artifacts/bindings-*/*.node |
| 190 | + env: |
| 191 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 192 | + - name: Publish to NPM |
| 193 | + run: | |
| 194 | + npm config set provenance true |
| 195 | + COMMIT_MSG=$(git log -1 --pretty=%B) |
| 196 | + if echo "$COMMIT_MSG" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$" > /dev/null; |
| 197 | + then |
| 198 | + echo "Publishing stable release to latest tag" |
| 199 | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc |
| 200 | + npm publish --access public |
| 201 | + elif echo "$COMMIT_MSG" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+" > /dev/null; |
| 202 | + then |
| 203 | + echo "Publishing pre-release to next tag" |
| 204 | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc |
| 205 | + npm publish --tag next --access public |
| 206 | + else |
| 207 | + echo "Invalid release tag format: '$COMMIT_MSG'" |
| 208 | + echo "Expected format: X.Y.Z or X.Y.Z-suffix" |
| 209 | + echo "Skipping publish" |
| 210 | + exit 0 |
| 211 | + fi |
| 212 | + env: |
| 213 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments