name: Docker # This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by # separate terms of service, privacy policy, and support # documentation. on: workflow_dispatch: push: branches: ["master", "dev", "v4"] tags: ["**"] pull_request: env: # Use docker.io for Docker Hub if empty REGISTRY: ghcr.io # github.repository as / IMAGE_NAME: ${{ github.repository }} permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: changelog: name: Changelog runs-on: ubuntu-latest outputs: changelog: ${{ steps.changelog.outputs.changelog }} permissions: contents: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - id: changelog run: | if [ "$HAS_TAG" = "true" ]; then { echo 'changelog<<__EOF__' python -c " import os version = os.environ['TAG'] print('\n'.join(open('CHANGELOG.md').read().split('## '+version)[1].split('\n')[1:]).split('\n##')[0]) " echo __EOF__ } >> "$GITHUB_OUTPUT" else echo "changelog=''" > "$GITHUB_OUTPUT" fi env: HAS_TAG: ${{ github.ref_type == 'tag' }} TAG: ${{ github.ref_name }} build: name: Build runs-on: ubuntu-latest permissions: contents: write packages: write # This is used to complete the identity challenge # with sigstore/fulcio when running outside of PRs. id-token: write attestations: write needs: changelog steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false # Install the cosign tool except on PR # https://github.com/sigstore/cosign-installer - name: Install cosign if: github.ref_type == 'tag' || github.ref_name == 'master' uses: sigstore/cosign-installer@881c63bd87e38389154debd8331404ce7ca8a3ab # v4.1.4 # Set up BuildKit Docker container builder to be able to build # multi-platform images and export cache # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 # Login against a Docker registry except on PR # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} if: github.ref_type == 'tag' || github.ref_name == 'master' uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} # Extract metadata (tags, labels) for Docker # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 with: context: . push: ${{ github.ref_type == 'tag' || github.ref_name == 'master' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} cache-from: type=gha cache-to: type=gha,mode=max provenance: true sbom: true outputs: type=oci,compression=zstd,compression-level=22,force-compression=true,dest=statustracker-${{ github.ref_name }}.tar.zst # Sign the resulting Docker image digest except on PRs. # This will only write to the public Rekor transparency log when the Docker # repository is public to avoid leaking data. If you would like to publish # transparency data even for private images, pass --force to cosign below. # https://github.com/sigstore/cosign - name: Sign the published Docker image if: github.ref_type == 'tag' || github.ref_name == 'master' env: # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable TAGS: ${{ steps.meta.outputs.tags }} DIGEST: ${{ steps.build-and-push.outputs.digest }} # This step uses the identity token to provision an ephemeral certificate # against the sigstore community Fulcio instance. run: echo "${TAGS}" | xargs -I {} cosign sign --yes "{}@${DIGEST}" - uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 if: github.ref_type == 'tag' with: subject-path: statustracker-${{ github.ref_name }}.tar.zst - uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3.0.4 # zizmor: ignore[superfluous-actions] if: github.ref_type == 'tag' with: body: ${{ needs.changelog.outputs.changelog }} files: statustracker-${{ github.ref_name }}.tar.zst delete-github-release: name: Delete failed release runs-on: ubuntu-slim needs: [changelog, build] if: always() && github.ref_type == 'tag' && contains(needs.*.result, 'failure') permissions: contents: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - run: gh release delete "$TAG" --cleanup-tag -y env: TAG: ${{ github.ref_name }} GH_TOKEN: ${{ github.token }} continue-on-error: true