Merge pull request #39 from Pagefind/pub'n #35
Workflow file for this run
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
| # Based on: https://github.com/ClementTsang/bottom/blob/master/.github/workflows/deployment.yml | |
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - v* | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| test-and-build: | |
| name: Test and Build | |
| runs-on: ${{matrix.os}} | |
| defaults: | |
| run: | |
| shell: bash | |
| strategy: | |
| matrix: | |
| include: | |
| - build: windows | |
| os: windows-latest | |
| rust: stable | |
| target: x86_64-pc-windows-msvc | |
| cross: false | |
| run_tests: true | |
| - build: linux | |
| os: ubuntu-latest | |
| rust: stable | |
| target: x86_64-unknown-linux-musl | |
| cross: false | |
| run_tests: true | |
| - build: linux | |
| os: ubuntu-latest | |
| rust: stable | |
| target: aarch64-unknown-linux-musl | |
| cross: false | |
| run_tests: false | |
| - build: macos | |
| os: macos-latest | |
| rust: stable | |
| target: x86_64-apple-darwin | |
| cross: false | |
| run_tests: true | |
| - build: macos-m1 | |
| os: macos-latest | |
| rust: stable | |
| target: aarch64-apple-darwin | |
| cross: false | |
| run_tests: false | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: 1 | |
| - name: Cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| ~/.rustup | |
| target | |
| key: ${{ runner.os }}-${{ matrix.rust }} | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 22 | |
| # From https://github.com/Emoun/duplicate/blob/master/.github/workflows/rust.yml | |
| - name: Get Version | |
| run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV | |
| - name: Verify Changelog | |
| run: | | |
| node ./.backstage/changelog.cjs | |
| - name: Install Linker | |
| if: matrix.cross | |
| run: | | |
| sudo apt update | |
| sudo apt install ${{ matrix.linker }} | |
| - name: Install Tooling | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt update -y | |
| sudo apt install -y musl-tools musl-dev clang gcc-aarch64-linux-gnu | |
| echo "TARGET_CC=clang" >> $GITHUB_ENV | |
| echo "CFLAGS_aarch64_unknown_linux_musl=--sysroot=/usr/aarch64-linux-gnu" >> $GITHUB_ENV | |
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/usr/aarch64-linux-gnu/bin/ld" >> $GITHUB_ENV | |
| - name: Install Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: ${{ matrix.rust }} | |
| target: ${{ matrix.target }} | |
| override: true | |
| default: true | |
| components: rustfmt, clippy | |
| - name: Ubuntu AppArmor fix | |
| if: ${{ matrix.os == 'ubuntu-latest' }} | |
| # Ubuntu >= 23 has AppArmor enabled by default, which breaks Chrome. | |
| # See https://github.com/puppeteer/puppeteer/issues/12818 "No usable sandbox!" | |
| # this is taken from the solution used in Puppeteer's CI: https://github.com/puppeteer/puppeteer/pull/13196 | |
| # The alternative is to pin Ubuntu 22 or to use aa-exec to disable AppArmor for commands that need Puppeteer. | |
| # This is also suggested by Chromium https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md | |
| run: | | |
| echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns | |
| shell: bash | |
| - name: Prepare Git | |
| run: | | |
| git config user.email "github@github.com" | |
| git config user.name "Github Actions" | |
| git checkout -b main | |
| # Use throw-away branch so we don't push the changes to origin | |
| git checkout -b deploy_branch | |
| - name: Prepare Crates | |
| run: | | |
| # Update cargo version, | |
| node ./.backstage/version.cjs | |
| git add ./toolproof/Cargo.toml | |
| # Commit changes so cargo doesn't complain about dirty repo | |
| git commit -m "Deploy changes." | |
| - name: Build | |
| working-directory: ./toolproof | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Test Lib | |
| if: matrix.run_tests == true | |
| working-directory: ./toolproof | |
| run: cargo test --release --target ${{ matrix.target }} | |
| - name: Test CLI | |
| if: matrix.run_tests == true | |
| working-directory: ./toolproof | |
| # toolproof tests itself when run | |
| run: cargo run -- --placeholders toolproof_path="$(pwd)/../target/debug/toolproof" -c 1 --timeout 60 | |
| # TODO: build and package pagebrowse | |
| - name: Create Release Assets | |
| run: | | |
| EXEC_NAME="toolproof" | |
| ASSET_PATH="$EXEC_NAME-v$GIT_VERSION-${{ matrix.target }}.tar.gz" | |
| CHECKSUM_PATH="$ASSET_PATH.sha256" | |
| if [ "$RUNNER_OS" == "Windows" ]; then | |
| EXEC_NAME="toolproof.exe" | |
| fi | |
| if command -v gtar &> /dev/null; then | |
| echo "Using gtar" | |
| gtar czf $ASSET_PATH -C target/${{ matrix.target }}/release $EXEC_NAME | |
| else | |
| echo "Using system tar" | |
| tar czf $ASSET_PATH -C target/${{ matrix.target }}/release $EXEC_NAME | |
| fi | |
| case $RUNNER_OS in | |
| Windows) | |
| sha256sum $ASSET_PATH > $CHECKSUM_PATH | |
| ;; | |
| Linux) | |
| sha256sum $ASSET_PATH > $CHECKSUM_PATH | |
| ;; | |
| macOS) | |
| shasum -a 256 $ASSET_PATH > $CHECKSUM_PATH | |
| ;; | |
| esac | |
| echo "ASSET_PATH=$ASSET_PATH" >> $GITHUB_ENV | |
| echo "CHECKSUM_PATH=$CHECKSUM_PATH" >> $GITHUB_ENV | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-${{ matrix.target }} | |
| path: | | |
| ${{ env.ASSET_PATH }} | |
| ${{ env.CHECKSUM_PATH }} | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-checksums-${{ matrix.target }} | |
| path: | | |
| ${{ env.CHECKSUM_PATH }} | |
| prepare-packages: | |
| name: Prepare Binary NPM Packages | |
| runs-on: ubuntu-24.04 | |
| needs: test-and-build | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-pc-windows-msvc | |
| package: windows-x64 | |
| os: win32 | |
| cpu: x64 | |
| - target: x86_64-unknown-linux-musl | |
| package: linux-x64 | |
| os: linux | |
| cpu: x64 | |
| - target: aarch64-unknown-linux-musl | |
| package: linux-arm64 | |
| os: linux | |
| cpu: arm64 | |
| - target: x86_64-apple-darwin | |
| package: darwin-x64 | |
| os: darwin | |
| cpu: x64 | |
| - target: aarch64-apple-darwin | |
| package: darwin-arm64 | |
| os: darwin | |
| cpu: arm64 | |
| steps: | |
| - name: Clone | |
| uses: actions/checkout@v2 | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 22 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: release-${{ matrix.target }} | |
| path: build-artifacts | |
| - name: Get Version | |
| run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV | |
| - name: Get Tag | |
| run: echo GIT_TAG="$(node ./.backstage/get_tag.cjs)" >> $GITHUB_ENV | |
| - name: Create Package | |
| run: | | |
| mkdir -p ${{ matrix.package }}/bin/ | |
| cd ${{ matrix.package }} | |
| node ../.backstage/create_package.cjs ${{ matrix.os }} ${{ matrix.cpu }} | |
| - name: Extract Binary | |
| working-directory: build-artifacts | |
| run: | | |
| tar xzf toolproof-v$GIT_VERSION-${{ matrix.target }}.tar.gz | |
| rm *.tar.gz | |
| mv * ../${{ matrix.package }}/bin/ | |
| - name: Prepare package | |
| working-directory: ${{ matrix.package }} | |
| run: | | |
| npm version $GIT_VERSION | |
| - name: Upload prepared package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: prepared-${{ matrix.package }} | |
| path: ${{ matrix.package }} | |
| publish: | |
| name: Publish | |
| runs-on: ubuntu-24.04 | |
| environment: production | |
| needs: prepare-packages | |
| permissions: | |
| id-token: write | |
| contents: write | |
| defaults: | |
| run: | |
| working-directory: ./ | |
| steps: | |
| # --- GitHub Release --- | |
| - name: Get Token | |
| id: get_workflow_token | |
| uses: peter-murray/workflow-application-token-action@v2 | |
| with: | |
| application_id: ${{ secrets.PF_BOT_ID }} | |
| application_private_key: ${{ secrets.PF_BOT_PEM }} | |
| - name: Clone | |
| uses: actions/checkout@v2 | |
| with: | |
| token: ${{ steps.get_workflow_token.outputs.token }} | |
| - name: Swap to main | |
| uses: actions/checkout@v2 | |
| with: | |
| ref: main | |
| fetch-depth: 0 # Full fetch | |
| token: ${{ steps.get_workflow_token.outputs.token }} | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 22 | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Get Version | |
| run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV | |
| - name: Get Tag | |
| run: echo GIT_TAG="$(node ./.backstage/get_tag.cjs)" >> $GITHUB_ENV | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: build-artifacts | |
| pattern: release-* | |
| merge-multiple: true | |
| - name: Build CHANGELOG | |
| if: env.GIT_TAG == 'latest' | |
| run: | | |
| node ./.backstage/changelog.cjs write | |
| echo CHANGELOG=\"$(base64 -w 0 -i CHANGELOG.md)\" >> $GITHUB_ENV | |
| echo SHA=\"$( git rev-parse main:CHANGELOG.md )\" >> $GITHUB_ENV | |
| - name: Build CHANGELOG | |
| if: env.GIT_TAG != 'latest' | |
| run: | | |
| echo "## Prerelease" > RELEASE.md | |
| node ./.backstage/changelog.cjs write || true | |
| - name: Commit new CHANGELOG | |
| uses: octokit/request-action@v2.x | |
| if: env.GIT_TAG == 'latest' | |
| id: push_changes | |
| with: | |
| route: PUT /repos/{owner}/{repo}/contents/CHANGELOG.md | |
| owner: pagefind | |
| repo: toolproof | |
| branch: main | |
| message: Changelog for ${{ env.GIT_VERSION }} | |
| sha: ${{ env.SHA }} | |
| content: ${{ env.CHANGELOG }} | |
| env: | |
| GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | |
| - name: Release documentation branch | |
| uses: octokit/request-action@v2.x | |
| if: env.GIT_TAG == 'latest' | |
| id: merge_docs | |
| with: | |
| route: POST /repos/{owner}/{repo}/merges | |
| owner: pagefind | |
| repo: toolproof | |
| base: production-docs | |
| head: main | |
| commit_message: Release documentation for ${{ env.GIT_VERSION }} | |
| env: | |
| GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | |
| - name: Release | |
| uses: softprops/action-gh-release@v1 | |
| if: startsWith(github.ref, 'refs/tags/') && env.GIT_TAG == 'latest' | |
| with: | |
| body_path: RELEASE.md | |
| files: | | |
| build-artifacts/* | |
| env: | |
| GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | |
| # --- Binary NPM Packages --- | |
| - name: Download prepared packages | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: prepared-* | |
| # --- Main NPM Package --- | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: wrappers/node/checksums | |
| pattern: release-checksums-* | |
| merge-multiple: true | |
| - name: Version optional dependencies | |
| run: | | |
| node ./.backstage/version_main_package.cjs | |
| - name: Prepare main NPM package | |
| working-directory: ./wrappers/node | |
| run: | | |
| npm version $GIT_VERSION | |
| - name: Publish binary NPM packages | |
| run: | | |
| for pkg in windows-x64 linux-x64 linux-arm64 darwin-x64 darwin-arm64; do | |
| echo "Publishing $pkg..." | |
| cd prepared-$pkg | |
| npm publish --provenance --tag $GIT_TAG --access public | |
| cd .. | |
| done | |
| - name: Publish main NPM package | |
| working-directory: ./wrappers/node | |
| run: npm publish --provenance --tag $GIT_TAG | |
| # --- Crate --- | |
| - name: Cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| ~/.rustup | |
| target | |
| key: ${{ runner.os }}-stable-min165 | |
| - name: Install Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| override: true | |
| default: true | |
| components: rustfmt, clippy | |
| - name: Prepare Git | |
| run: | | |
| git config user.email "github@github.com" | |
| git config user.name "Github Actions" | |
| # Use throw-away branch so we don't push the changes to origin | |
| git checkout -b deploy_branch | |
| - name: Prepare Crates | |
| run: | | |
| # Update cargo version, | |
| node ./.backstage/version.cjs | |
| git add ./toolproof/Cargo.toml | |
| # Commit changes so cargo doesn't complain about dirty repo | |
| git commit -m "Deploy changes." | |
| - name: Build | |
| run: cargo build --release --verbose | |
| - name: Publish Crate | |
| working-directory: ./toolproof | |
| run: cargo publish --allow-dirty | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |