name: On Release Published on: release: types: - released jobs: build-and-release: name: Build, Publish, and Finalize Stable Release runs-on: ubuntu-latest permissions: contents: write packages: write steps: - name: Checkout Repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 1 ref: ${{ github.sha }} - name: Set Up QEMU for Multi-Arch Builds uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 with: cache-image: false - name: Set Up Docker Buildx uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0 - name: Authenticate to Docker Hub if: ${{ vars.DOCKERHUB_REGISTRY != '' }} uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Authenticate to GitHub Container Registry uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - name: Docker meta id: meta uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 with: images: | ${{ vars.DOCKERHUB_REGISTRY }} ghcr.io/${{ github.repository }} tags: | type=semver,pattern=v{{version}},value=${{ github.event.release.tag_name }},match=^v(.+)$ type=semver,pattern=v{{major}}.{{minor}},value=${{ github.event.release.tag_name }},match=^v(.+)$ - name: Build and push Stable image uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 with: context: . file: Dockerfile platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} annotations: ${{ steps.meta.outputs.annotations }} build-args: | APP_VERSION=${{ github.event.release.tag_name }} APP_REVISION=${{ github.sha }} cache-from: | type=gha,scope=image-shared type=registry,ref=ghcr.io/${{ github.repository }}:buildcache cache-to: | type=gha,scope=image-shared,mode=max type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max publish-helm-chart: name: Publish Helm Chart to GHCR needs: - build-and-release runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout Repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 1 ref: ${{ github.sha }} - name: Set Up Helm uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 - name: Authenticate to GitHub Container Registry uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - name: Package and Push Helm Chart env: RELEASE_TAG: ${{ github.event.release.tag_name }} run: | set -eu VERSION="${RELEASE_TAG#v}" helm dependency update deploy/helm/grimmory helm package deploy/helm/grimmory \ --version "${VERSION}" \ --app-version "${RELEASE_TAG}" helm push "grimmory-${VERSION}.tgz" "oci://ghcr.io/${{ github.repository_owner }}/helm-charts" prepare-release-notification: name: Prepare Stable Release Notification needs: - build-and-release runs-on: ubuntu-latest outputs: base_tag: ${{ steps.metadata.outputs.base_tag }} compare_url: ${{ steps.metadata.outputs.compare_url }} available: ${{ steps.webhook_secrets_check.outputs.available }} permissions: contents: read steps: - name: Check Discord Webhook secrets id: webhook_secrets_check env: DISCORD_WEBHOOK: ${{ secrets.DISCORD_STABLE_WEBHOOK }} run: | # Check here rather than in the `if`. # Github actions does not support the `secrets` context in `if` blocks. if [[ -n "${DISCORD_WEBHOOK}" ]]; then echo "available=true" >> $GITHUB_OUTPUT else echo "available=false" >> $GITHUB_OUTPUT fi - name: Checkout Repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 ref: ${{ github.event.release.tag_name }} - name: Extract Stable Release Metadata id: metadata if: ${{ steps.webhook_secrets_check.outputs.available == 'true' }} env: RELEASE_TAG: ${{ github.event.release.tag_name }} RELEASE_URL: ${{ github.event.release.html_url }} run: | set -eu git fetch origin main --tags --force BASE_TAG="$(git tag --sort=-version:refname 'v*' | grep -Fxv "$RELEASE_TAG" | head -n 1 || true)" COMPARE_URL="${RELEASE_URL}" if [ -n "$BASE_TAG" ]; then COMPARE_URL="https://github.com/${GITHUB_REPOSITORY}/compare/${BASE_TAG}...${RELEASE_TAG}" fi { echo "base_tag=${BASE_TAG}" echo "compare_url=${COMPARE_URL}" } >> "$GITHUB_OUTPUT" notify-discord: name: Notify Discord Release needs: - prepare-release-notification - publish-helm-chart if: ${{ needs.prepare-release-notification.outputs.available == 'true' }} permissions: {} uses: ./.github/workflows/notify-discord-release-notes.yml secrets: discord_webhook: ${{ secrets.DISCORD_STABLE_WEBHOOK }} with: channel: stable current_version: ${{ github.event.release.tag_name }} predicted_version: ${{ github.event.release.tag_name }} details_url: ${{ github.event.release.html_url }} candidate_sha: ${{ github.sha }} base_tag: ${{ needs.prepare-release-notification.outputs.base_tag }} compare_url: ${{ needs.prepare-release-notification.outputs.compare_url }} mention_text: ${{ vars.DISCORD_STABLE_MENTIONS }}