Publish release #15
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: Publish release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'The version number to tag and release' | |
| required: true | |
| type: string | |
| prerelease: | |
| description: 'Release as pre-release' | |
| required: false | |
| type: boolean | |
| default: false | |
| jobs: | |
| build-libraries: | |
| name: Build Libraries (${{ matrix.name }}) | |
| permissions: | |
| contents: read | |
| strategy: | |
| matrix: | |
| include: | |
| - name: Linux x64 | |
| os: ubuntu-latest | |
| cambi: cambi-linux | |
| artifact: milo-parser-lib-linux | |
| - name: macOS arm64 | |
| os: macos-latest | |
| cambi: cambi-macos-arm | |
| artifact: milo-parser-lib-macos-arm | |
| - name: macOS x64 | |
| os: macos-15-intel | |
| cambi: cambi-macos-intel | |
| artifact: milo-parser-lib-macos-intel | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Use supported Rust version | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: nightly | |
| - name: Use supported Node.js version | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 26 | |
| - name: Restore cached dependencies (Cargo) | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| parser/target | |
| macros/target | |
| key: cargo-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Restore cached dependencies (PNPM) | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.pnpm-store | |
| key: release-node-${{ hashFiles('package.json') }}-${{ hashFiles('pnpm-lock.yaml') }} | |
| - name: Install makers | |
| uses: taiki-e/cache-cargo-install-action@v3 | |
| with: | |
| tool: cargo-make | |
| - name: Install cbindgen | |
| uses: taiki-e/cache-cargo-install-action@v3 | |
| with: | |
| tool: cbindgen | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: latest | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Download latest cambi | |
| shell: bash | |
| run: | | |
| mkdir -p /tmp/cambi-bootstrap | |
| gh release download --repo ShogunPanda/cambi --pattern "${{ matrix.cambi }}" --dir /tmp/cambi-bootstrap | |
| chmod +x "/tmp/cambi-bootstrap/${{ matrix.cambi }}" | |
| ln -sf "/tmp/cambi-bootstrap/${{ matrix.cambi }}" /tmp/cambi-bootstrap/cambi | |
| echo "/tmp/cambi-bootstrap" >> "$GITHUB_PATH" | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Build C++ artifacts | |
| shell: bash | |
| run: | | |
| node scripts/sync-versions.js $(cambi update "${{ inputs.version }}" -s) | |
| cd parser | |
| makers cpp | |
| - name: Package C++ artifacts | |
| shell: bash | |
| run: | | |
| mkdir -p /tmp/${{ matrix.artifact }} | |
| cp dist/cpp/release/milo.h /tmp/${{ matrix.artifact }}/milo.h | |
| cp dist/cpp/release/libmilo.a /tmp/${{ matrix.artifact }}/libmilo.a | |
| tar -C /tmp -czf /tmp/${{ matrix.artifact }}.tar.gz ${{ matrix.artifact }} | |
| - name: Upload C++ artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact }} | |
| path: /tmp/${{ matrix.artifact }}.tar.gz | |
| build-binaries: | |
| name: Build Binary (${{ matrix.name }}) | |
| permissions: | |
| contents: read | |
| strategy: | |
| matrix: | |
| include: | |
| - name: Linux x64 | |
| os: ubuntu-latest | |
| cambi: cambi-linux | |
| artifact: milo-parser-bin-linux | |
| - name: macOS arm64 | |
| os: macos-latest | |
| cambi: cambi-macos-arm | |
| artifact: milo-parser-bin-macos-arm | |
| - name: macOS x64 | |
| os: macos-15-intel | |
| cambi: cambi-macos-intel | |
| artifact: milo-parser-bin-macos-intel | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Use supported Rust version | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: nightly | |
| - name: Use supported Node.js version | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 26 | |
| - name: Restore cached dependencies (Cargo) | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| parser/target | |
| macros/target | |
| key: cargo-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Download latest cambi | |
| shell: bash | |
| run: | | |
| mkdir -p /tmp/cambi-bootstrap | |
| gh release download --repo ShogunPanda/cambi --pattern "${{ matrix.cambi }}" --dir /tmp/cambi-bootstrap | |
| chmod +x "/tmp/cambi-bootstrap/${{ matrix.cambi }}" | |
| ln -sf "/tmp/cambi-bootstrap/${{ matrix.cambi }}" /tmp/cambi-bootstrap/cambi | |
| echo "/tmp/cambi-bootstrap" >> "$GITHUB_PATH" | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Build binary | |
| shell: bash | |
| run: | | |
| node scripts/sync-versions.js $(cambi update "${{ inputs.version }}" -s) | |
| cd parser | |
| cargo build --release --bin milo-parser | |
| - name: Package binary | |
| shell: bash | |
| run: | | |
| mkdir -p /tmp/${{ matrix.artifact }} | |
| cp parser/target/release/milo-parser /tmp/${{ matrix.artifact }}/milo-parser | |
| tar -C /tmp -czf /tmp/${{ matrix.artifact }}.tar.gz ${{ matrix.artifact }} | |
| - name: Upload binary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact }} | |
| path: /tmp/${{ matrix.artifact }}.tar.gz | |
| release: | |
| name: Release | |
| environment: main | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-libraries | |
| - build-binaries | |
| permissions: | |
| id-token: write | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| fetch-depth: 0 | |
| - name: Use supported Rust version | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: nightly | |
| components: rust-src | |
| - name: Add Rust targets | |
| run: rustup target add wasm32-unknown-unknown | |
| - name: Use supported Node.js version | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 26 | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install Binaryen | |
| run: | | |
| curl -sSL -o binaryen.tar.gz https://github.com/WebAssembly/binaryen/releases/download/version_123/binaryen-version_123-x86_64-linux.tar.gz | |
| tar -xzf binaryen.tar.gz | |
| echo "$PWD/binaryen-version_123/bin" >> "$GITHUB_PATH" | |
| "$PWD/binaryen-version_123/bin/wasm-opt" --version | |
| - name: Restore cached dependencies (Cargo) | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| parser/target | |
| macros/target | |
| key: cargo-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Restore cached dependencies (PNPM) | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.pnpm-store | |
| key: release-node-${{ hashFiles('package.json') }}-${{ hashFiles('pnpm-lock.yaml') }} | |
| - name: Install makers | |
| run: | | |
| ARCH=x86_64-unknown-linux-gnu | |
| MAKERS_VERSION=$(curl -sSL https://api.github.com/repos/sagiegurari/cargo-make/releases/latest | yq .tag_name | sed "s#v##") | |
| curl -sSL -o /tmp/makers.zip "https://github.com/sagiegurari/cargo-make/releases/latest/download/cargo-make-v$MAKERS_VERSION-$ARCH.zip" | |
| unzip -d /tmp /tmp/makers.zip | |
| echo "/tmp/cargo-make-v$MAKERS_VERSION-$ARCH" >> "$GITHUB_PATH" | |
| - name: Install makers | |
| uses: taiki-e/cache-cargo-install-action@v3 | |
| with: | |
| tool: cargo-make | |
| - name: Install cbindgen | |
| uses: taiki-e/cache-cargo-install-action@v3 | |
| with: | |
| tool: cbindgen | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: latest | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Download latest cambi | |
| run: | | |
| mkdir -p /tmp/cambi-bootstrap | |
| gh release download --repo ShogunPanda/cambi --pattern cambi-linux --dir /tmp/cambi-bootstrap | |
| chmod +x /tmp/cambi-bootstrap/cambi-linux | |
| ln -sf /tmp/cambi-bootstrap/cambi-linux /tmp/cambi-bootstrap/cambi | |
| echo "/tmp/cambi-bootstrap" >> "$GITHUB_PATH" | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Setup cargo OIDC | |
| uses: rust-lang/crates-io-auth-action@v1 | |
| id: auth | |
| - name: Configure git | |
| run: | | |
| git config --global user.name "${{ github.actor }}" | |
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
| - name: Prepare release | |
| run: | | |
| node scripts/sync-versions.js $(cambi update "${{ inputs.version }}" -s) | |
| cambi update -l "${{ inputs.version }}" | |
| (cd macros && cargo generate-lockfile) | |
| (cd parser && cargo generate-lockfile) | |
| (cd references/rust && cargo generate-lockfile) | |
| - name: Build WASM package | |
| run: | | |
| cd parser | |
| makers wasm | |
| - name: Download C++ artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: /tmp/artifacts | |
| - name: Prepare GitHub release assets | |
| run: | | |
| mkdir -p /tmp/release | |
| mv /tmp/artifacts/milo-parser-lib-linux/milo-parser-lib-linux.tar.gz /tmp/release/ | |
| mv /tmp/artifacts/milo-parser-lib-macos-arm/milo-parser-lib-macos-arm.tar.gz /tmp/release/ | |
| mv /tmp/artifacts/milo-parser-lib-macos-intel/milo-parser-lib-macos-intel.tar.gz /tmp/release/ | |
| mv /tmp/artifacts/milo-parser-bin-linux/milo-parser-bin-linux.tar.gz /tmp/release/ | |
| mv /tmp/artifacts/milo-parser-bin-macos-arm/milo-parser-bin-macos-arm.tar.gz /tmp/release/ | |
| mv /tmp/artifacts/milo-parser-bin-macos-intel/milo-parser-bin-macos-intel.tar.gz /tmp/release/ | |
| - name: Push release commit and tag | |
| run: | | |
| git add -f package.json CHANGELOG.md parser/Cargo.toml parser/Cargo.lock macros/Cargo.toml macros/Cargo.lock references/rust/Cargo.toml references/rust/Cargo.lock parser/src/wasm/package.json | |
| git commit -m "chore: Updated version." | |
| git tag -f "v${{ inputs.version }}" | |
| - name: Publish macros on crates.io | |
| run: cargo publish | |
| working-directory: macros | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} | |
| - name: Publish parser on crates.io | |
| run: cargo publish | |
| working-directory: parser | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} | |
| - name: Publish WASM ESM package on npm | |
| run: pnpm publish --access public --tag ${{ inputs.prerelease == true && 'next' || 'latest' }} --provenance --no-git-checks | |
| working-directory: dist/wasm/release/package | |
| - name: Publish WASM CJS package on npm | |
| run: pnpm publish --access public --tag ${{ inputs.prerelease == true && 'next' || 'latest' }} --provenance --no-git-checks | |
| working-directory: dist/wasm/release/package-cjs | |
| - name: Publish on GitHub | |
| run: | | |
| cambi release -n > /tmp/release-notes.txt | |
| git push origin && git push origin -f --tags | |
| gh release create "v${{ inputs.version }}" -t "${{ inputs.version }}" ${{ github.event.inputs.prerelease == 'true' && '--prerelease' || '' }} -F /tmp/release-notes.txt /tmp/release/* | |
| env: | |
| GH_TOKEN: ${{ github.token }} |