Bump version to 3.20.12 #112
This file contains 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: build from source | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
- dev | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
paths: | |
- .github/workflows/build.yaml | |
- build/* | |
pull_request: | |
paths: | |
- .github/workflows/build.yaml | |
- build/* | |
# Pattern matched against refs/tags | |
env: | |
DOCKER_REPO: ghcr.io/belphemur/protonmail-bridge | |
DOCKER_REPO_DEV: ghcr.io/belphemur/protonmail-bridge-dev | |
REGISTRY: ghcr.io | |
jobs: | |
version: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
repo: ${{ steps.repo.outputs.repo }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: 'build/VERSION' | |
sparse-checkout-cone-mode: false | |
- name: Set version | |
id: version | |
run: echo "version=$(cat build/VERSION)" >> $GITHUB_OUTPUT | |
- name: Set repo | |
id: repo | |
run: | | |
if [[ $GITHUB_REF == "refs/heads/master" || $GITHUB_REF == refs/tags/* ]]; then | |
echo "repo=${DOCKER_REPO}" >> $GITHUB_OUTPUT | |
else | |
echo "repo=${DOCKER_REPO_DEV}" >> $GITHUB_OUTPUT | |
fi | |
build: | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
actions: read | |
security-events: write | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- platform: "linux/amd64" | |
scan: true | |
needs_qemu: false | |
- platform: "linux/arm64" | |
scan: false | |
needs_qemu: true | |
services: | |
registry: | |
image: registry:2 | |
ports: | |
- 5000:5000 | |
needs: | |
- version | |
steps: | |
- name: Prepare | |
run: | | |
platform=${{ matrix.platform }} | |
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
echo "SCOPE=${{needs.version.outputs.repo}}-${platform//\//-}" >> $GITHUB_ENV | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{needs.version.outputs.repo}} | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up QEMU | |
if: matrix.needs_qemu | |
uses: docker/setup-qemu-action@v3 | |
# Workaround: https://github.com/docker/build-push-action/issues/461 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: network=host | |
- name: Build image without push to registry ${{ matrix.platform }} | |
uses: docker/build-push-action@v6 | |
if: matrix.scan | |
with: | |
context: ./build | |
file: ./build/Dockerfile | |
platforms: ${{ matrix.platform }} | |
push: true | |
tags: localhost:5000/protonmail-bridge:latest | |
cache-from: type=gha,scope=${{ env.SCOPE }} | |
cache-to: type=gha,mode=max,scope=${{ env.SCOPE }} | |
build-args: | | |
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
VCS_REF=$(git rev-parse --short HEAD) | |
VERSION=${{needs.version.outputs.version}} | |
- name: Scan image | |
id: scan | |
uses: anchore/scan-action@v5 | |
if: matrix.scan | |
with: | |
image: localhost:5000/protonmail-bridge:latest | |
fail-build: true | |
severity-cutoff: critical | |
output-format: sarif | |
add-cpes-if-none: true | |
- name: Upload Anchore scan SARIF report | |
uses: github/codeql-action/upload-sarif@v3 | |
if: matrix.scan && always() | |
with: | |
sarif_file: ${{ steps.scan.outputs.sarif }} | |
- name: Build and push Docker image ${{ matrix.platform }} | |
id: build-and-push | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./build | |
file: ./build/Dockerfile | |
platforms: ${{ matrix.platform }} | |
labels: ${{ steps.meta.outputs.labels }} | |
outputs: type=image,name=${{needs.version.outputs.repo}},push-by-digest=true,name-canonical=true,push=true | |
cache-from: type=gha,scope=${{ env.SCOPE }} | |
cache-to: type=gha,mode=max,scope=${{ env.SCOPE }} | |
build-args: | | |
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
VCS_REF=$(git rev-parse --short HEAD) | |
VERSION=${{needs.version.outputs.version}} | |
- | |
name: Export digest | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.build-and-push.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- | |
name: Upload digest | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests-${{ env.PLATFORM_PAIR }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge: | |
permissions: | |
contents: read | |
packages: write | |
# Used for attestation | |
id-token: write | |
attestations: write | |
if: github.event_name != 'pull_request' | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
- version | |
steps: | |
- | |
name: Download digests | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/digests | |
pattern: digests-* | |
merge-multiple: true | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{needs.version.outputs.repo}} | |
tags: | | |
type=semver,pattern={{version}},value=${{needs.version.outputs.version}} | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
$(printf '${{needs.version.outputs.repo}}@sha256:%s ' *) | |
- | |
name: Inspect image | |
run: | | |
docker buildx imagetools inspect ${{needs.version.outputs.repo}}:${{ steps.meta.outputs.version }} | |
- | |
name: Export digest | |
id: digest | |
run: | | |
echo digest=$(docker buildx imagetools inspect ghcr.io/belphemur/protonmail-bridge:latest --format "{{json .Manifest.Digest}}" | xargs) >> $GITHUB_OUTPUT | |
- | |
name: Attest | |
uses: actions/attest-build-provenance@v1 | |
id: attest | |
with: | |
subject-name: ${{needs.version.outputs.repo}} | |
subject-digest: ${{ steps.digest.outputs.digest }} | |
push-to-registry: true |