v0.1.4 #2
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
| name: Release | |
| on: | |
| release: | |
| types: [created] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: Version without the v prefix (for example, 0.1.4) | |
| required: true | |
| type: string | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: release-${{ github.event.release.tag_name || inputs.version }} | |
| cancel-in-progress: false | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-22.04 | |
| outputs: | |
| source_sha: ${{ steps.source.outputs.sha }} | |
| version: ${{ steps.source.outputs.version }} | |
| tag: ${{ steps.source.outputs.tag }} | |
| publish: ${{ steps.source.outputs.publish }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Validate release inputs | |
| id: source | |
| shell: bash | |
| env: | |
| RELEASE_TAG: ${{ github.event.release.tag_name }} | |
| INPUT_VERSION: ${{ inputs.version }} | |
| run: | | |
| if [[ -n "$RELEASE_TAG" ]]; then | |
| [[ "$RELEASE_TAG" == v* ]] || { echo "Release tag must start with v" >&2; exit 1; } | |
| TAG="$RELEASE_TAG" | |
| VERSION="${TAG#v}" | |
| SOURCE_SHA="$(git rev-parse "${RELEASE_TAG}^{commit}")" | |
| PUBLISH=true | |
| else | |
| VERSION="$INPUT_VERSION" | |
| TAG="v${VERSION}" | |
| SOURCE_SHA="$(git rev-parse HEAD)" | |
| PUBLISH=false | |
| fi | |
| [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]] || { echo "Invalid semantic version" >&2; exit 1; } | |
| { | |
| echo "sha=$SOURCE_SHA" | |
| echo "version=$VERSION" | |
| echo "tag=$TAG" | |
| echo "publish=$PUBLISH" | |
| } >> "$GITHUB_OUTPUT" | |
| build: | |
| needs: prepare | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - {target: x86_64-unknown-linux-gnu, os: ubuntu-22.04} | |
| - {target: aarch64-unknown-linux-gnu, os: ubuntu-22.04} | |
| - {target: x86_64-apple-darwin, os: macos-15} | |
| - {target: aarch64-apple-darwin, os: macos-15} | |
| - {target: x86_64-pc-windows-msvc, os: windows-2022} | |
| runs-on: ${{ matrix.os }} | |
| env: | |
| VERSION: ${{ needs.prepare.outputs.version }} | |
| TAG: ${{ needs.prepare.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.prepare.outputs.source_sha }} | |
| persist-credentials: false | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu | |
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" | |
| - name: Set package version | |
| shell: bash | |
| run: | | |
| sed -i.bak -E "s/^version = \".*\"/version = \"${VERSION}\"/" Cargo.toml | |
| cargo update -p ptd-cli | |
| - name: Test | |
| if: matrix.target == 'x86_64-unknown-linux-gnu' | |
| run: cargo test --locked | |
| - name: Build | |
| run: cargo build --locked --release --target "${{ matrix.target }}" | |
| - name: Smoke test native executable | |
| if: matrix.target == 'x86_64-unknown-linux-gnu' | |
| run: target/${{ matrix.target }}/release/ptd --help | |
| - name: Package Unix binaries | |
| if: runner.os != 'Windows' | |
| run: tar -C "target/${{ matrix.target }}/release" -czf "ptd-cli-${TAG}-${{ matrix.target }}.tar.gz" ptd ptd-host | |
| - name: Package Windows binaries | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: Compress-Archive -Path "target/${{ matrix.target }}/release/ptd.exe","target/${{ matrix.target }}/release/ptd-host.exe" -DestinationPath "ptd-cli-$env:TAG-${{ matrix.target }}.zip" | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-${{ matrix.target }} | |
| path: ptd-cli-${{ env.TAG }}-${{ matrix.target }}.* | |
| if-no-files-found: error | |
| compatibility: | |
| name: Ubuntu 22.04 and Homebrew smoke test | |
| needs: [prepare, build] | |
| runs-on: ubuntu-22.04 | |
| env: | |
| VERSION: ${{ needs.prepare.outputs.version }} | |
| TAG: ${{ needs.prepare.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.prepare.outputs.source_sha }} | |
| persist-credentials: false | |
| - uses: Homebrew/actions/setup-homebrew@a657b8b0cd35d0f65cce41fce9b24cf054b49869 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: release-x86_64-unknown-linux-gnu | |
| path: dist | |
| - name: Test packaged executable and formula | |
| shell: bash | |
| run: | | |
| tar -xzf "dist/ptd-cli-${TAG}-x86_64-unknown-linux-gnu.tar.gz" -C dist | |
| dist/ptd --help | |
| SHA="$(sha256sum "dist/ptd-cli-${TAG}-x86_64-unknown-linux-gnu.tar.gz" | awk '{print $1}')" | |
| sed -e "s/@VERSION@/${VERSION}/g" \ | |
| -e "s|@REPOSITORY@|${GITHUB_REPOSITORY}|g" \ | |
| -e "s|@LINUX_X86_64_URL@|file://${GITHUB_WORKSPACE}/dist/ptd-cli-${TAG}-x86_64-unknown-linux-gnu.tar.gz|g" \ | |
| -e "s/@LINUX_X86_64_SHA@/${SHA}/g" \ | |
| .github/release/ptd-cli.rb.in > /tmp/ptd-cli.rb | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| brew tap-new ptd-test/release | |
| cp /tmp/ptd-cli.rb "$(brew --repository ptd-test/release)/Formula/ptd-cli.rb" | |
| brew install --formula ptd-test/release/ptd-cli | |
| brew test ptd-test/release/ptd-cli | |
| publish: | |
| name: Publish assets, then manifests | |
| needs: [prepare, build, compatibility] | |
| if: needs.prepare.outputs.publish == 'true' | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| contents: write | |
| env: | |
| VERSION: ${{ needs.prepare.outputs.version }} | |
| TAG: ${{ needs.prepare.outputs.tag }} | |
| GH_TOKEN: ${{ github.token }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.repository.default_branch }} | |
| fetch-depth: 0 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: release-* | |
| path: dist | |
| merge-multiple: true | |
| - name: Upload and verify every release asset | |
| shell: bash | |
| run: | | |
| gh release upload "$TAG" dist/* --clobber | |
| ASSETS="$(gh release view "$TAG" --json assets --jq '.assets[].name')" | |
| for asset in dist/*; do grep -Fxq "$(basename "$asset")" <<< "$ASSETS"; done | |
| - name: Generate release manifests | |
| run: .github/release/render-manifests.sh "$VERSION" "$TAG" "$GITHUB_REPOSITORY" dist | |
| - name: Publish release metadata idempotently | |
| shell: bash | |
| run: | | |
| git pull --ff-only origin "${{ github.event.repository.default_branch }}" | |
| mkdir -p Formula bucket | |
| cp generated/ptd-cli.rb Formula/ptd-cli.rb | |
| cp generated/ptd-cli.json bucket/ptd-cli.json | |
| git add Formula/ptd-cli.rb bucket/ptd-cli.json | |
| if git diff --cached --quiet; then echo "Release metadata is already current"; exit 0; fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git commit -m "chore(release): publish ${TAG} [skip ci]" | |
| git push origin HEAD:${{ github.event.repository.default_branch }} |