snap: require GITHUB_SHA for version suffix (#214) #529
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: ci | |
| on: | |
| push: | |
| branches: [ main, stable ] | |
| tags: | |
| - 'v*' | |
| paths-ignore: | |
| - docs/** | |
| - README.md.md | |
| - CHANGELOG.md | |
| pull_request: | |
| branches: [ main, stable ] | |
| paths-ignore: | |
| - docs/** | |
| - README.md.md | |
| - CHANGELOG.md | |
| env: | |
| REGISTRY_IMAGE: reduct/store | |
| jobs: | |
| rust_fmt: | |
| runs-on: ubuntu-latest | |
| name: Rust Linter | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check code | |
| run: cargo fmt --all -- --check | |
| build: | |
| name: Build binaries | |
| needs: | |
| - rust_fmt | |
| strategy: | |
| matrix: | |
| target: | |
| [ | |
| "x86_64-unknown-linux-gnu", | |
| "aarch64-unknown-linux-gnu", | |
| "armv7-unknown-linux-gnueabihf", | |
| "x86_64-pc-windows-gnu", | |
| "x86_64-apple-darwin", | |
| "aarch64-apple-darwin", | |
| ] | |
| include: | |
| - target: "x86_64-unknown-linux-gnu" | |
| os: ubuntu-24.04 | |
| compiler: "gcc" | |
| - target: "aarch64-unknown-linux-gnu" | |
| os: ubuntu-24.04 | |
| compiler: "gcc-aarch64-linux-gnu" | |
| - target: "armv7-unknown-linux-gnueabihf" | |
| os: ubuntu-24.04 | |
| compiler: "gcc-arm-linux-gnueabihf" | |
| - target: "x86_64-pc-windows-gnu" | |
| os: ubuntu-24.04 | |
| compiler: "gcc-mingw-w64-x86-64" | |
| - target: "x86_64-apple-darwin" | |
| os: macos-14 | |
| compiler: "gcc-x86_64-apple-darwin" | |
| - target: "aarch64-apple-darwin" | |
| os: macos-14 | |
| compiler: "gcc" | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: ${{ vars.MINIMAL_RUST_VERSION }} | |
| target: ${{ matrix.target }} | |
| - name: Install gcc | |
| if: ${{ matrix.os == 'ubuntu-24.04' }} | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ${{ matrix.compiler }} | |
| - name: Install gcc | |
| if: ${{ matrix.os == 'macos-latest' }} | |
| run: | | |
| brew install ${{ matrix.compiler }} | |
| - name: AWS Credentials and Cargo Cache | |
| uses: ./.github/actions/aws-cargo-cache | |
| with: | |
| target: ${{ matrix.target }} | |
| profile: release | |
| access-key-id: ${{ secrets.S3_CACHE_ACCESS_KEY }} | |
| secret-access-key: ${{ secrets.S3_CACHE_SECRET_KEY }} | |
| - name: Build binary | |
| env: | |
| RUSTFLAGS: "-C target-feature=+crt-static" | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Upload binary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: reduct-cli-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/reduct-cli${{ matrix.target == 'x86_64-pc-windows-gnu' && '.exe' || '' }} | |
| cli_tests: | |
| name: Client CLI Tests | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: ${{ vars.MINIMAL_RUST_VERSION }} | |
| - name: AWS Credentials and Cargo Cache | |
| uses: ./.github/actions/aws-cargo-cache | |
| with: | |
| target: x86_64-unknown-linux-gnu | |
| profile: ci | |
| access-key-id: ${{ secrets.S3_CACHE_ACCESS_KEY }} | |
| secret-access-key: ${{ secrets.S3_CACHE_SECRET_KEY }} | |
| - name: Run ReductStore | |
| run: docker run --network=host -v ${PWD}/misc:/misc --env RS_API_TOKEN=TOKEN -d ${{env.REGISTRY_IMAGE}}:main | |
| - name: Run Client CLI tests | |
| run: RS_API_TOKEN=TOKEN cargo test -- --test-threads=1 | |
| check_tag: | |
| runs-on: ubuntu-latest | |
| name: Check tag | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check tag | |
| if: startsWith(github.ref, 'refs/tags/') | |
| run: | | |
| cargo install cargo-get | |
| if [ "v$(cargo get package.version)" != "${GITHUB_REF#refs/*/}" ]; then | |
| echo "Tag does not match version in $PKG_NAME/Cargo.toml" | |
| exit 1 | |
| fi | |
| publish_crate: | |
| runs-on: ubuntu-latest | |
| name: Publish crate | |
| needs: | |
| - cli_tests | |
| - build | |
| - check_tag # Only publish on tags | |
| if: startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: ${{ vars.MINIMAL_RUST_VERSION }} | |
| - name: Login | |
| run: | | |
| cargo login ${{ secrets.CRATES_IO_TOKEN }} | |
| - name: Publish reduct-cli | |
| run: cargo publish -p reduct-cli --allow-dirty | |
| make_release: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build | |
| - cli_tests | |
| - check_tag # Only publish on tags | |
| outputs: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| name: Make release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - uses: softprops/action-gh-release@v2 | |
| id: create_release | |
| with: | |
| draft: true | |
| prerelease: false | |
| name: Release ${{ github.ref_name }} | |
| tag_name: ${{ github.ref_name }} | |
| body: Copy changes from CHANGELOG.md | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| upload_release: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - make_release | |
| name: Upload artifacts | |
| if: startsWith(github.ref, 'refs/tags/') | |
| strategy: | |
| matrix: | |
| target: [ | |
| "x86_64-unknown-linux-gnu", | |
| "aarch64-unknown-linux-gnu", | |
| "armv7-unknown-linux-gnueabihf", | |
| "x86_64-pc-windows-gnu", | |
| "x86_64-apple-darwin", | |
| "aarch64-apple-darwin", | |
| ] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download ${{ matrix.target }} artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: reduct-cli-${{ matrix.target }} | |
| path: /tmp/ | |
| - name: Archive binary for UNIX | |
| if: ${{ matrix.target != 'x86_64-pc-windows-gnu' }} | |
| run: | | |
| cd /tmp | |
| tar -czvf reduct-cli.${{ matrix.target }}.tar.gz reduct-cli | |
| - name: Archive binary for Windows | |
| if: ${{ matrix.target == 'x86_64-pc-windows-gnu' }} | |
| run: | | |
| cd /tmp | |
| zip -o reduct-cli.${{ matrix.target }}.zip reduct-cli.exe | |
| - name: Upload Linux Unix artifact | |
| if: ${{ matrix.target != 'x86_64-pc-windows-gnu' }} | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.make_release.outputs.upload_url }} | |
| asset_path: /tmp/reduct-cli.${{ matrix.target }}.tar.gz | |
| asset_name: reduct-cli.${{ matrix.target }}.tar.gz | |
| asset_content_type: application/gzip | |
| - name: Upload Windows artifact | |
| if: ${{ matrix.target == 'x86_64-pc-windows-gnu' }} | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.make_release.outputs.upload_url }} | |
| asset_path: /tmp/reduct-cli.${{ matrix.target }}.zip | |
| asset_name: reduct-cli.${{ matrix.target }}.zip | |
| asset_content_type: application/zip | |
| snap_release: | |
| name: Build and Publish Snap Package | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| arch: [ amd64, arm64 ] | |
| needs: | |
| - build | |
| - cli_tests | |
| - check_tag | |
| if: github.event_name != 'pull_request' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: ./.github/actions/snap-release | |
| with: | |
| arch: ${{ matrix.arch }} | |
| - name: Publish snap package | |
| uses: snapcore/action-publish@master | |
| env: | |
| SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }} | |
| with: | |
| snap: ${{ env.SNAP_NAME }} | |
| release: ${{ startsWith(github.ref, 'refs/tags/') && 'stable' || 'edge' }} |