Release Build and Publish #21
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 Build and Publish | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| pull_request: | |
| paths: | |
| - "**/*.rs" | |
| - "**/Cargo.toml" | |
| - "Cargo.lock" | |
| - "flake.nix" | |
| workflow_dispatch: | |
| inputs: | |
| release_name: | |
| description: "Name of release (optional)" | |
| required: false | |
| default: "" | |
| create_release: | |
| description: "Create a GitHub release? (true/false)" | |
| required: false | |
| default: "false" | |
| create_binaries: | |
| description: "Create a Binaries? (true/false)" | |
| required: false | |
| default: "false" | |
| create_images: | |
| description: "Create a Docker Images? (true/false)" | |
| required: false | |
| default: "false" | |
| jobs: | |
| generate-matrix: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.generate-matrix.outputs.matrix }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v30 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| github_access_token: ${{ secrets.GITHUB_TOKEN }} | |
| extra_nix_config: | | |
| experimental-features = nix-command flakes | |
| - name: Generate matrix | |
| id: generate-matrix | |
| run: | | |
| MATRIX=$(nix run .#matrix --quiet) | |
| echo "Generated Matrix:" | |
| echo "$MATRIX" | |
| echo "matrix=$MATRIX" >> $GITHUB_OUTPUT | |
| ARCH_LIST=$(echo "$MATRIX" | jq -r '.[].arch' | jq -R -s -c 'split("\n") | map(select(. != ""))') | |
| echo "arch_list=$ARCH_LIST" >> $GITHUB_OUTPUT | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: generate-matrix | |
| if: ${{ github.event.inputs.create_binaries == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} | |
| env: | |
| ARTIFACT_NAME: "" | |
| VERSION: ${{ github.event.inputs.release_name || github.ref_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v30 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| github_access_token: ${{ secrets.GITHUB_TOKEN }} | |
| extra_nix_config: | | |
| experimental-features = nix-command flakes | |
| - name: Set up artifact name | |
| run: | | |
| echo "ARTIFACT_NAME=grhooks_${{ env.VERSION }}_${{ matrix.os }}_${{ matrix.arch }}.${{ matrix.format }}" >> $GITHUB_ENV | |
| - name: Build package | |
| run: | | |
| echo "Building ${{ matrix.package }} for ${{ matrix.arch }}-${{ matrix.os }}..." | |
| nix bundle --bundler "${{ matrix.bundler }}" ".#${{ matrix.package }}" --out-link result | |
| mkdir -p dist | |
| cp result/*${{ matrix.format }} dist/${{ env.ARTIFACT_NAME }} | |
| - name: Upload Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.ARTIFACT_NAME }} | |
| path: dist/* | |
| create-release: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: ${{ github.event.inputs.create_release == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Generate changelog | |
| uses: orhun/git-cliff-action@v4 | |
| id: git-cliff | |
| with: | |
| config: cliff.toml | |
| args: --latest | |
| env: | |
| OUTPUT: CHANGES.md | |
| GITHUB_REPO: ${{ github.repository }} | |
| - name: Get release name | |
| id: release_name | |
| run: | | |
| if [ -n "${{ github.event.inputs.release_name }}" ]; then | |
| echo "RELEASE_NAME=${{ github.event.inputs.release_name }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "RELEASE_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Download Artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: true | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| make_latest: true | |
| prerelease: ${{ steps.release_name.outputs.release_name != '' && contains(steps.release_name.outputs.release_name, 'a') }} | |
| tag_name: ${{ steps.release_name.outputs.release_name }} | |
| name: ${{ steps.release_name.outputs.release_name }} | |
| body: ${{ steps.git-cliff.outputs.content }} | |
| files: | | |
| artifacts/* | |
| CHANGES.md | |
| docker-build: | |
| runs-on: ubuntu-latest | |
| needs: [generate-matrix] | |
| if: ${{ github.event.inputs.create_images == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} | |
| env: | |
| VERSION: ${{ github.event.inputs.release_name || github.ref_name }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set Repository Lowercase | |
| run: echo "REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v30 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| github_access_token: ${{ secrets.GITHUB_TOKEN }} | |
| extra_nix_config: | | |
| experimental-features = nix-command flakes | |
| - name: Build individual images with Nix | |
| run: | | |
| nix build .#image-${{ matrix.arch }} | |
| docker load < ./result | |
| docker tag grhooks:${{ env.VERSION }} ghcr.io/${{ env.REPOSITORY }}/grhooks:${{ matrix.arch }} | |
| - name: Create and push unified manifest | |
| run: | | |
| docker manifest create ghcr.io/${{ env.REPOSITORY }}/grhooks:${{ env.VERSION }} \ | |
| --amend ghcr.io/${{ env.REPOSITORY }}/grhooks:${{ matrix.arch }} | |
| docker-publish: | |
| runs-on: ubuntu-latest | |
| needs: [generate-matrix, docker-build] | |
| env: | |
| VERSION: ${{ github.event.inputs.release_name || github.ref_name }} | |
| steps: | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set Repository Lowercase | |
| run: echo "REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| - name: Create and push manifest | |
| run: | | |
| IMAGE=ghcr.io/${{ env.REPOSITORY }}/grhooks:${{ env.VERSION }} | |
| ARCHS='${{ needs.generate-matrix.outputs.arch_list }}' | |
| echo "Creating manifest for architectures: $ARCHS" | |
| manifest_args="" | |
| for arch in $(echo "$ARCHS" | jq -r '.[]'); do | |
| manifest_args="$manifest_args --amend ghcr.io/${{ env.REPOSITORY }}/grhooks:$arch" | |
| done | |
| echo "Running docker manifest create $IMAGE $manifest_args" | |
| eval docker manifest create $IMAGE $manifest_args | |
| docker manifest push $IMAGE |