|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build (${{ matrix.target }}) |
| 14 | + runs-on: ${{ matrix.runner }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - target: aarch64-apple-darwin |
| 20 | + runner: macos-14 |
| 21 | + npm-pkg: getapi-cli-darwin-arm64 |
| 22 | + cross: false |
| 23 | + - target: x86_64-apple-darwin |
| 24 | + runner: macos-13 |
| 25 | + npm-pkg: getapi-cli-darwin-x64 |
| 26 | + cross: false |
| 27 | + - target: x86_64-unknown-linux-gnu |
| 28 | + runner: ubuntu-latest |
| 29 | + npm-pkg: getapi-cli-linux-x64 |
| 30 | + cross: false |
| 31 | + - target: aarch64-unknown-linux-gnu |
| 32 | + runner: ubuntu-latest |
| 33 | + npm-pkg: getapi-cli-linux-arm64 |
| 34 | + cross: true |
| 35 | + - target: x86_64-pc-windows-msvc |
| 36 | + runner: windows-latest |
| 37 | + npm-pkg: getapi-cli-win32-x64 |
| 38 | + cross: false |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - uses: dtolnay/rust-toolchain@stable |
| 43 | + if: ${{ !matrix.cross }} |
| 44 | + with: |
| 45 | + targets: ${{ matrix.target }} |
| 46 | + |
| 47 | + - uses: Swatinem/rust-cache@v2 |
| 48 | + with: |
| 49 | + key: ${{ matrix.target }} |
| 50 | + |
| 51 | + - name: Install cross |
| 52 | + if: ${{ matrix.cross }} |
| 53 | + run: cargo install cross --git https://github.com/cross-rs/cross |
| 54 | + |
| 55 | + - name: Build binary |
| 56 | + run: ${{ matrix.cross && 'cross' || 'cargo' }} build --release --target ${{ matrix.target }} |
| 57 | + |
| 58 | + - name: Prepare artifacts (Unix) |
| 59 | + if: runner.os != 'Windows' |
| 60 | + run: | |
| 61 | + BIN="target/${{ matrix.target }}/release/getapi" |
| 62 | + chmod +x "$BIN" |
| 63 | +
|
| 64 | + # Raw binary for npm |
| 65 | + mkdir -p npm-bin |
| 66 | + cp "$BIN" npm-bin/getapi |
| 67 | +
|
| 68 | + # Archive for GitHub Release |
| 69 | + ARCHIVE="getapi-${{ matrix.target }}.tar.gz" |
| 70 | + tar czf "$ARCHIVE" -C "target/${{ matrix.target }}/release" getapi |
| 71 | +
|
| 72 | + - name: Prepare artifacts (Windows) |
| 73 | + if: runner.os == 'Windows' |
| 74 | + shell: pwsh |
| 75 | + run: | |
| 76 | + $BIN = "target/${{ matrix.target }}/release/getapi.exe" |
| 77 | +
|
| 78 | + # Raw binary for npm |
| 79 | + New-Item -ItemType Directory -Force -Path npm-bin |
| 80 | + Copy-Item $BIN npm-bin/getapi.exe |
| 81 | +
|
| 82 | + # Archive for GitHub Release |
| 83 | + Compress-Archive -Path $BIN -DestinationPath "getapi-${{ matrix.target }}.zip" |
| 84 | +
|
| 85 | + - name: Upload binary artifact (npm) |
| 86 | + uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: bin-${{ matrix.npm-pkg }} |
| 89 | + path: npm-bin/ |
| 90 | + |
| 91 | + - name: Upload release archive |
| 92 | + uses: actions/upload-artifact@v4 |
| 93 | + with: |
| 94 | + name: archive-${{ matrix.target }} |
| 95 | + path: getapi-${{ matrix.target }}.* |
| 96 | + |
| 97 | + github-release: |
| 98 | + needs: build |
| 99 | + runs-on: ubuntu-latest |
| 100 | + steps: |
| 101 | + - uses: actions/download-artifact@v4 |
| 102 | + with: |
| 103 | + pattern: archive-* |
| 104 | + merge-multiple: true |
| 105 | + |
| 106 | + - name: Create GitHub Release |
| 107 | + uses: softprops/action-gh-release@v2 |
| 108 | + with: |
| 109 | + generate_release_notes: true |
| 110 | + files: | |
| 111 | + getapi-*.tar.gz |
| 112 | + getapi-*.zip |
| 113 | +
|
| 114 | + publish-crates: |
| 115 | + needs: build |
| 116 | + runs-on: ubuntu-latest |
| 117 | + steps: |
| 118 | + - uses: actions/checkout@v4 |
| 119 | + |
| 120 | + - uses: dtolnay/rust-toolchain@stable |
| 121 | + |
| 122 | + - name: Publish to crates.io |
| 123 | + run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 124 | + |
| 125 | + publish-npm: |
| 126 | + needs: build |
| 127 | + runs-on: ubuntu-latest |
| 128 | + steps: |
| 129 | + - uses: actions/checkout@v4 |
| 130 | + |
| 131 | + - uses: actions/setup-node@v4 |
| 132 | + with: |
| 133 | + node-version: '20' |
| 134 | + registry-url: 'https://registry.npmjs.org' |
| 135 | + |
| 136 | + - name: Download all binary artifacts |
| 137 | + uses: actions/download-artifact@v4 |
| 138 | + with: |
| 139 | + pattern: bin-* |
| 140 | + path: artifacts |
| 141 | + |
| 142 | + - name: Stage binaries into platform packages |
| 143 | + run: | |
| 144 | + PLATFORMS=( |
| 145 | + "getapi-cli-darwin-arm64" |
| 146 | + "getapi-cli-darwin-x64" |
| 147 | + "getapi-cli-linux-x64" |
| 148 | + "getapi-cli-linux-arm64" |
| 149 | + "getapi-cli-win32-x64" |
| 150 | + ) |
| 151 | +
|
| 152 | + for pkg in "${PLATFORMS[@]}"; do |
| 153 | + mkdir -p "npm/${pkg}/bin" |
| 154 | + cp artifacts/bin-${pkg}/* "npm/${pkg}/bin/" |
| 155 | +
|
| 156 | + # chmod +x on Unix binaries |
| 157 | + if [[ "$pkg" != *"win32"* ]]; then |
| 158 | + chmod +x "npm/${pkg}/bin/getapi" |
| 159 | + fi |
| 160 | + done |
| 161 | +
|
| 162 | + - name: Publish platform packages |
| 163 | + env: |
| 164 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 165 | + run: | |
| 166 | + PLATFORMS=( |
| 167 | + "getapi-cli-darwin-arm64" |
| 168 | + "getapi-cli-darwin-x64" |
| 169 | + "getapi-cli-linux-x64" |
| 170 | + "getapi-cli-linux-arm64" |
| 171 | + "getapi-cli-win32-x64" |
| 172 | + ) |
| 173 | +
|
| 174 | + for pkg in "${PLATFORMS[@]}"; do |
| 175 | + echo "Publishing ${pkg}..." |
| 176 | + cd "npm/${pkg}" |
| 177 | + npm publish --access public |
| 178 | + cd ../.. |
| 179 | + done |
| 180 | +
|
| 181 | + - name: Publish shim package |
| 182 | + env: |
| 183 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 184 | + run: | |
| 185 | + cd npm/getapi-cli |
| 186 | + npm publish --access public |
| 187 | +
|
| 188 | + update-homebrew: |
| 189 | + needs: github-release |
| 190 | + runs-on: ubuntu-latest |
| 191 | + steps: |
| 192 | + - uses: mislav/bump-homebrew-formula-action@v3 |
| 193 | + with: |
| 194 | + formula-name: getapi |
| 195 | + homebrew-tap: m2de/homebrew-tap |
| 196 | + download-url: https://github.com/m2de/getapi/archive/refs/tags/${{ github.ref_name }}.tar.gz |
| 197 | + env: |
| 198 | + COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
0 commit comments