Final fix #31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - package.json | |
| - Cargo.toml | |
| jobs: | |
| create-release: | |
| name: Create a new github release | |
| permissions: | |
| contents: write | |
| runs-on: ubuntu-latest | |
| outputs: | |
| upload_url: ${{ steps.get-u-url.outputs.result }} | |
| release_id: ${{ steps.get-id.outputs.result }} | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Create Release | |
| id: create-release | |
| uses: actions/github-script@v7 | |
| env: | |
| BRANCH: ${{ github.ref_name }} | |
| with: | |
| script: | | |
| const fs = require("fs"); | |
| const version = require('./package.json').version; | |
| const { data } = await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: version, | |
| name: `AHQ Store CLI Binaries v${version}`, | |
| body: String(fs.readFileSync("./latest.md")), | |
| draft: true, | |
| prerelease: false | |
| }); | |
| return data | |
| - name: Get Release Id | |
| id: get-id | |
| uses: actions/github-script@v7 | |
| env: | |
| data: ${{ steps.create-release.outputs.result }} | |
| with: | |
| result-encoding: string | |
| script: | | |
| let data = process.env.data; | |
| try { | |
| data = JSON.parse(data); | |
| console.log(data.id); | |
| return data.id; | |
| } catch (_) { | |
| console.log(data.id); | |
| return data.id; | |
| } | |
| - name: Get Upload Url | |
| id: get-u-url | |
| uses: actions/github-script@v7 | |
| env: | |
| data: ${{ steps.create-release.outputs.result }} | |
| with: | |
| result-encoding: string | |
| script: | | |
| let data = process.env.data; | |
| try { | |
| data = JSON.parse(data); | |
| return data.upload_url; | |
| } catch (_) { | |
| return data.upload_url; | |
| } | |
| cargo: | |
| name: Publish to cargo | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Setup Cargo | |
| run: rustup toolchain add stable | |
| - name: Publish | |
| run: cargo publish --allow-dirty | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }} | |
| build: | |
| name: Build CLI and Dylib | |
| needs: [create-release] | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| - os: ubuntu-latest | |
| target: i686-unknown-linux-gnu | |
| - os: ubuntu-latest | |
| target: aarch64-unknown-linux-gnu | |
| - os: ubuntu-latest | |
| target: armv7-unknown-linux-gnueabihf | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| - os: windows-latest | |
| target: i686-pc-windows-msvc | |
| - os: windows-latest | |
| target: aarch64-pc-windows-msvc | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Setup Rust Nightly | |
| run: | | |
| rustup toolchain add nightly | |
| rustup default nightly | |
| rustup target add ${{ matrix.target }} | |
| - name: Linux Cross Platform | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install zip gcc-aarch64-linux-gnu gcc-i686-linux-gnu gcc-arm-linux-gnueabihf | |
| - name: Build | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Bundle CLI | |
| run: | | |
| ./bundle.ps1 | |
| shell: pwsh | |
| env: | |
| TARGET: ${{ matrix.target }} | |
| - name: Upload to Releases | |
| uses: AButler/[email protected] | |
| with: | |
| release-id: ${{ needs.create-release.outputs.release_id }} | |
| files: ./ahqstore_cli_rs-${{ matrix.target }}.zip | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload to Releases (UNIX based) | |
| uses: AButler/[email protected] | |
| if: matrix.os == 'ubuntu-latest' | |
| with: | |
| release-id: ${{ needs.create-release.outputs.release_id }} | |
| files: ./libahqstore_cli_rs-${{ matrix.target }}.so | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload to Releases (Windows based) | |
| uses: AButler/[email protected] | |
| if: matrix.os == 'windows-latest' | |
| with: | |
| release-id: ${{ needs.create-release.outputs.release_id }} | |
| files: ./ahqstore_cli_rs-${{ matrix.target }}.dll | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload to Releases (MacOS based) | |
| uses: AButler/[email protected] | |
| if: matrix.os == 'macos-latest' | |
| with: | |
| release-id: ${{ needs.create-release.outputs.release_id }} | |
| files: ./libahqstore_cli_rs-${{ matrix.target }}.dylib | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| npm: | |
| name: Publish to npmjs | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Setup node | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 22 | |
| - name: Setup pnpm | |
| run: npm i -g pnpm | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Publish | |
| run: | | |
| npm config set provenance true | |
| echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc | |
| npm publish --access public | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| publish: | |
| needs: [create-release, build, npm, cargo] | |
| name: Publish Release | |
| runs-on: ubuntu-latest | |
| if: success() | |
| steps: | |
| - name: Undraft Release | |
| uses: actions/github-script@v7 | |
| env: | |
| R_ID: ${{ needs.create-release.outputs.release_id }} | |
| with: | |
| script: | | |
| github.rest.repos.updateRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: process.env.R_ID, | |
| draft: false | |
| }); | |
| unpublish: | |
| name: Unpublish this release | |
| runs-on: ubuntu-latest | |
| needs: [create-release, build, npm, cargo] | |
| if: failure() | |
| steps: | |
| - name: Delete Release | |
| uses: actions/github-script@v7 | |
| env: | |
| R_ID: ${{ needs.create-release.outputs.release_id }} | |
| with: | |
| script: | | |
| github.rest.repos.deleteRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: process.env.R_ID, | |
| }); |