chore: add new release (#61) #36
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
| # Release modern workflow with crates.io Trusted Publishing. | ||
| # Use this to test the new flow. On crates.io add Trusted Publisher with workflow filename: release.yml | ||
| # Manual only: run from Actions → Release → Run workflow, and select the version tag (e.g. v0.1.0) as the ref. | ||
| name: Release | ||
| on: | ||
| workflow_dispatch: | ||
| # Uncomment this to release on tag push | ||
| # push: | ||
| # tags: | ||
| # - 'v[0-9]+.[0-9]+.[0-9]+' | ||
| inputs: | ||
| tag: | ||
| description: 'Release tag (must already exist in the repo, e.g. v0.1.0)' | ||
| required: true | ||
| type: string | ||
| env: | ||
| BIN_NAME: scopelint | ||
| PROJECT_NAME: scopelint | ||
| REPO_NAME: ScopeLift/scopelint | ||
| jobs: | ||
| dist: | ||
| name: Dist | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: true | ||
| matrix: | ||
| build: [x86_64-linux, aarch64-linux, x86_64-macos, x86_64-windows, aarch64-macos] | ||
| include: | ||
| - build: x86_64-linux | ||
| os: ubuntu-22.04 | ||
| rust: stable | ||
| target: x86_64-unknown-linux-gnu | ||
| cross: true | ||
| - build: aarch64-linux | ||
| os: ubuntu-22.04 | ||
| rust: stable | ||
| target: aarch64-unknown-linux-gnu | ||
| cross: true | ||
| - build: x86_64-macos | ||
| os: macos-latest | ||
| rust: stable | ||
| target: x86_64-apple-darwin | ||
| cross: true | ||
| - build: x86_64-windows | ||
| os: windows-2019 | ||
| rust: stable | ||
| target: x86_64-pc-windows-msvc | ||
| cross: true | ||
| - build: aarch64-macos | ||
| os: macos-latest | ||
| rust: stable | ||
| target: aarch64-apple-darwin | ||
| cross: true | ||
| steps: | ||
| - name: Checkout sources | ||
| uses: actions/checkout@v4 | ||
| - name: Install ${{ matrix.rust }} toolchain | ||
| uses: actions-rs/toolchain@v1 | ||
| with: | ||
| profile: minimal | ||
| toolchain: ${{ matrix.rust }} | ||
| target: ${{ matrix.target }} | ||
| override: true | ||
| - name: Build release binary | ||
| uses: actions-rs/cargo@v1 | ||
| with: | ||
| use-cross: ${{ matrix.cross }} | ||
| command: build | ||
| args: --release --locked --target ${{ matrix.target }} | ||
| - name: Strip release binary (linux and macos) | ||
| if: matrix.build == 'x86_64-linux' || matrix.build == 'x86_64-macos' | ||
| run: strip "target/${{ matrix.target }}/release/$BIN_NAME" | ||
| - name: Strip release binary (arm) | ||
| if: matrix.build == 'aarch64-linux' | ||
| run: | | ||
| docker run --rm -v \ | ||
| "$PWD/target:/target:Z" \ | ||
| rustembedded/cross:${{ matrix.target }} \ | ||
| aarch64-linux-gnu-strip \ | ||
| /target/${{ matrix.target }}/release/$BIN_NAME | ||
| - name: Build archive | ||
| shell: bash | ||
| run: | | ||
| mkdir dist | ||
| if [ "${{ matrix.os }}" = "windows-2019" ]; then | ||
| cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "dist/" | ||
| else | ||
| cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/" | ||
| fi | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: bins-${{ matrix.build }} | ||
| path: dist | ||
| publish: | ||
| name: Publish | ||
| needs: [dist] | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write # Required to create releases and upload assets | ||
| id-token: write # Required for crates.io Trusted Publishing (OIDC) | ||
| steps: | ||
| - name: Checkout sources | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: false | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: 'bins-*' | ||
| merge-multiple: false | ||
| - run: ls -al bins-* | ||
| - name: Calculate tag name | ||
| run: | | ||
| name="${{ inputs.tag }}" | ||
| if [[ -z "$name" || "$name" != v* ]]; then | ||
| echo "::error::Release tag must be set and start with 'v' (e.g. v0.1.0)" | ||
| exit 1 | ||
| fi | ||
| echo "val=$name" >> $GITHUB_OUTPUT | ||
| echo TAG=$name >> $GITHUB_ENV | ||
| id: tagname | ||
| - name: Build archive | ||
| shell: bash | ||
| run: | | ||
| set -ex | ||
| rm -rf tmp | ||
| mkdir tmp | ||
| mkdir dist | ||
| for dir in bins-* ; do | ||
| platform=${dir#"bins-"} | ||
| unset exe | ||
| if [[ $platform =~ "windows" ]]; then | ||
| exe=".exe" | ||
| fi | ||
| pkgname=$PROJECT_NAME-$platform | ||
| mkdir tmp/$pkgname | ||
| mv bins-$platform/$BIN_NAME$exe tmp/$pkgname | ||
| chmod +x tmp/$pkgname/$BIN_NAME$exe | ||
| if [ "$exe" = "" ]; then | ||
| tar cJf dist/$pkgname.tar.xz -C tmp $pkgname | ||
| else | ||
| (cd tmp && 7z a -r ../dist/$pkgname.zip $pkgname) | ||
| fi | ||
| done | ||
| - name: Upload binaries to release | ||
| uses: svenstaro/upload-release-action@v2 | ||
| with: | ||
| repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
| file: dist/* | ||
| file_glob: true | ||
| tag: ${{ steps.tagname.outputs.val }} | ||
| overwrite: true | ||
| - name: Authenticate with crates.io | ||
| id: auth | ||
| uses: rust-lang/crates-io-auth-action@v1 | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@stable | ||
| - name: Publish to crates.io | ||
| run: cargo publish --allow-dirty | ||
| env: | ||
| CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} | ||