name: Nightly - Build and Publish on: schedule: - cron: '0 4 * * *' workflow_dispatch: inputs: post_discord: description: 'Post the Discord nightly announcement' required: false type: boolean default: false jobs: resolve_ref: name: Resolve Nightly Ref runs-on: ubuntu-latest permissions: actions: read contents: read outputs: commit_sha: ${{ steps.resolve.outputs.commit_sha }} from_ref: ${{ steps.resolve.outputs.from_ref }} nightly_tag: ${{ steps.resolve.outputs.nightly_tag }} steps: - name: Checkout Repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Record Resolved Commit id: resolve env: GH_TOKEN: ${{ github.token }} run: | set -eu git fetch origin main --tags --force short_sha="$(git rev-parse --short HEAD)" build_date="$(date -u +%Y%m%d)" nightly_tag="nightly-${build_date}-${short_sha}" from_ref="$(git describe --tags --abbrev=0 --match 'v*' origin/main)" echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" echo "from_ref=${from_ref}" >> "$GITHUB_OUTPUT" echo "nightly_tag=${nightly_tag}" >> "$GITHUB_OUTPUT" build-and-push: name: Build and Push Nightly Image needs: [resolve_ref, test-suite] runs-on: ubuntu-latest permissions: contents: read packages: write outputs: image_tag: ${{ steps.record.outputs.image_tag }} steps: - name: Checkout Repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 1 ref: ${{ needs.resolve_ref.outputs.commit_sha }} - name: Record Nightly Build Metadata id: record env: NIGHTLY_TAG: ${{ needs.resolve_ref.outputs.nightly_tag }} run: | echo "image_tag=${NIGHTLY_TAG}" >> "$GITHUB_OUTPUT" echo "nightly_tag=${NIGHTLY_TAG}" >> "$GITHUB_ENV" echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_ENV" echo "Nightly tag: ${NIGHTLY_TAG}" - name: Set Up QEMU for Multi-Arch Builds uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 with: cache-image: false - name: Set Up Docker Buildx uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 - name: Authenticate to Docker Hub if: ${{ vars.DOCKERHUB_REGISTRY != '' }} uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Authenticate to GitHub Container Registry uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.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=raw,value=nightly type=raw,value=${{ env.nightly_tag }} - 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=${{ env.nightly_tag }} APP_REVISION=${{ env.commit_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 export-openapi: name: Export Nightly OpenAPI Artifact needs: [resolve_ref] runs-on: ubuntu-latest permissions: contents: read steps: - name: Checkout Workflow Repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 1 ref: ${{ needs.resolve_ref.outputs.commit_sha }} - name: Export OpenAPI JSON uses: ./.github/actions/export-openapi with: checkout_ref: ${{ needs.resolve_ref.outputs.commit_sha }} app_version: ${{ needs.resolve_ref.outputs.nightly_tag }} - name: Upload Nightly OpenAPI Artifact uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: openapi-${{ needs.resolve_ref.outputs.nightly_tag }} path: backend/build/openapi/grimmory-openapi.json retention-days: 30 generate-notes: name: Generate Notes needs: - resolve_ref uses: ./.github/workflows/compute-release-notes.yml permissions: contents: read with: from-ref: ${{ needs.resolve_ref.outputs.from_ref }} to-ref: ${{ needs.resolve_ref.outputs.commit_sha }} secrets: inherit notify-discord: name: Notify Discord (Nightly) if: ${{ always() && (github.event_name == 'schedule' || inputs.post_discord) && needs.generate-notes.result == 'success' && needs.build-and-push.result == 'success' && needs.export-openapi.result == 'success' }} needs: - resolve_ref - build-and-push - export-openapi - generate-notes permissions: {} uses: ./.github/workflows/notify-discord-release-notes.yml secrets: discord_webhook: ${{ secrets.DISCORD_NIGHTLY_WEBHOOK != '' && secrets.DISCORD_NIGHTLY_WEBHOOK || secrets.DISCORD_RELEASE_WEBHOOK }} with: channel: nightly candidate_sha: ${{ needs.resolve_ref.outputs.commit_sha }} current_version: ${{ needs.resolve_ref.outputs.nightly_tag }} details_url: ${{ needs.generate-notes.outputs.details-url }} compare_url: ${{ needs.generate-notes.outputs.compare-url }} mention_text: ${{ vars.DISCORD_NIGHTLY_MENTIONS }} predicted_version: ${{ needs.generate-notes.outputs.version }} test-suite: name: Test Suite needs: [resolve_ref] uses: ./.github/workflows/test-suite.yml permissions: contents: read checks: write with: checkout_ref: ${{ needs.resolve_ref.outputs.commit_sha }}