Skip to content

Add GitHub Actions security scanning with CodeQL and zizmor (#115) #337

Add GitHub Actions security scanning with CodeQL and zizmor (#115)

Add GitHub Actions security scanning with CodeQL and zizmor (#115) #337

Workflow file for this run

name: CI
on: [push, pull_request]
permissions:
contents: read
jobs:
test:
env:
MIX_ENV: test
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
with:
persist-credentials: false
- uses: erlef/setup-beam@ee09b1e59bb240681c382eb1f0abc6a04af72764 # v1.23.0
with:
otp-version: 27.2
elixir-version: 1.18.1
- run: mix deps.get
- run: mix format --check-formatted
- run: mix deps.unlock --check-unused
- run: MIX_ENV=test mix compile --warnings-as-errors
- run: mix test
docker:
name: Docker (${{ matrix.platform }})
runs-on: ${{ matrix.runner }}
permissions:
contents: 'read'
id-token: 'write'
strategy:
matrix:
include:
- platform: linux/amd64
runner: ubuntu-24.04
- platform: linux/arm64
runner: ubuntu-24.04-arm
env:
IMAGE_NAME: 'diff'
PROJECT_ID: 'hexpm-prod'
SERVICE_ACCOUNT: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCLOUD_WORKFLOW_IDENTITY_POOL_PROVIDER }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Google auth
id: auth
uses: 'google-github-actions/auth@c200f3691d83b41bf9bbd8638997a462592937ed' # v2.1.13
if: ${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
with:
token_format: 'access_token'
project_id: ${{ env.PROJECT_ID }}
service_account: ${{ env.SERVICE_ACCOUNT }}
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
- name: Docker Auth
id: docker-auth
uses: 'docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9' # v3.7.0
if: ${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
with:
registry: gcr.io
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.access_token }}'
- name: Build and push by digest
id: build
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
platforms: ${{ matrix.platform }}
outputs: type=image,name=gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
cache-from: type=gha,scope=${{ matrix.runner }}
cache-to: type=gha,scope=${{ matrix.runner }},mode=max
- name: Export digest
if: ${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
run: |
mkdir -p /tmp/digests
digest="${DIGEST}"
touch "/tmp/digests/${digest#sha256:}"
env:
DIGEST: ${{ steps.build.outputs.digest }}
- name: Upload digest
if: ${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: digests-${{ matrix.runner }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
docker-merge:
name: Docker Merge
runs-on: ubuntu-24.04
if: ${{ github.event_name != 'pull_request' && github.repository == 'hexpm/diff' }}
needs: docker
permissions:
contents: 'read'
id-token: 'write'
env:
IMAGE_NAME: 'diff'
PROJECT_ID: 'hexpm-prod'
SERVICE_ACCOUNT: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCLOUD_WORKFLOW_IDENTITY_POOL_PROVIDER }}
steps:
- name: Set short git commit SHA
run: echo "COMMIT_SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: Download digests
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: Google auth
id: auth
uses: 'google-github-actions/auth@c200f3691d83b41bf9bbd8638997a462592937ed' # v2.1.13
with:
token_format: 'access_token'
project_id: ${{ env.PROJECT_ID }}
service_account: ${{ env.SERVICE_ACCOUNT }}
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
- name: Docker Auth
uses: 'docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9' # v3.7.0
with:
registry: gcr.io
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.access_token }}'
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
-t gcr.io/${PROJECT_ID}/${IMAGE_NAME}:${COMMIT_SHORT_SHA} \
$(printf 'gcr.io/${PROJECT_ID}/${IMAGE_NAME}@sha256:%s ' *)