ci(gha): remove develop branch and ignore on main (#935) #1306
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 and publish docker artifacts | |
on: | |
push: | |
branches: [ main ] | |
tags: | |
- '[0-9]+.[0-9]+.[0-9]+*' | |
pull_request: | |
types: [ opened, synchronize ] | |
paths: | |
- 'Earthfile' | |
- '.github/workflows/docker-builds.yaml' | |
- 'services/credential-server-ui/**' | |
- 'services/credential-server/**' | |
workflow_dispatch: | |
inputs: | |
images: | |
description: 'Select which earthly targets to build and push' | |
required: true | |
default: 'all' | |
type: choice | |
options: | |
- idw-keria | |
- idw-witness | |
- cred-issuance | |
- cred-issuance-ui | |
- cip45-sample-dapp | |
- all | |
env: | |
DOCKER_PUSH: true | |
jobs: | |
set-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: set-matrix | |
id: set-matrix | |
run: | | |
echo 'matrix={"platform":["linux/amd64","linux/arm64"]}' | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
build-n-publish: | |
needs: set-matrix | |
permissions: | |
contents: read | |
packages: write | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{fromJson(needs.set-matrix.outputs.matrix)}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup qemu for arm builds | |
uses: docker/setup-qemu-action@v3 | |
if: matrix.platform == 'linux/arm64' | |
with: | |
platforms: arm64 | |
- name: ⛮ cf-gha-baseline | |
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main | |
id: cf-gha-baseline | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }} | |
PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token | |
PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} | |
HUB_DOCKER_COM_USER: ${{ secrets.HUB_DOCKER_COM_USER }} | |
HUB_DOCKER_COM_PASS: ${{ secrets.HUB_DOCKER_COM_PASS }} | |
DOCKER_REGISTRIES: "${{ secrets.DOCKER_REGISTRIES }}" | |
- name: Set docker image targets based on path changes from last commit | |
id: metadata | |
run: | | |
set -x | |
if [ ${{github.event_name}} == "workflow_dispatch" ] | |
then | |
case "${{ github.event.inputs.images }}" in | |
idw-keria) | |
DOCKER_IMAGES_TARGETS="idw-keria" | |
;; | |
idw-witness) | |
DOCKER_IMAGES_TARGETS="idw-witness" | |
;; | |
cred-issuance) | |
DOCKER_IMAGES_TARGETS="cred-issuance" | |
;; | |
cred-issuance-ui) | |
DOCKER_IMAGES_TARGETS="cred-issuance-ui" | |
;; | |
cip45-sample-dapp) | |
DOCKER_IMAGES_TARGETS="cip45-sample-dapp" | |
;; | |
all) | |
DOCKER_IMAGES_TARGETS="idw-keria idw-witness cred-issuance cred-issuance-ui cip45-sample-dapp" | |
;; | |
*) | |
echo "Invalid option, exiting..." | |
exit 1 | |
;; | |
esac | |
echo "DOCKER_IMAGES_TARGETS=${DOCKER_IMAGES_TARGETS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
echo "DOCKER_IMAGES_TARGETS_$(echo ${{ matrix.platform }} | sed 's|/|_|g')=${DOCKER_IMAGES_TARGETS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
fi | |
if [ ${{github.event_name}} == "pull_request" ] | |
then | |
git checkout ${BRANCH_NAME} | |
# set earthly docker image targets based on changed paths | |
set +e | |
DOCKER_IMAGES_TARGETS="$( \ | |
( git log --pretty=format:'%h' -n 1 Earthfile | grep -q ${PR_GIT_SHORT_COMMIT} ) && \ | |
( git log --patch -n1 Earthfile | grep -q "^[+-]ARG.*global.*KERIA_" ) && \ | |
echo idw-keria | |
)" | |
DOCKER_IMAGES_TARGETS="$DOCKER_IMAGES_TARGETS $( \ | |
( git log --pretty=format:'%h' -n 1 Earthfile | grep -q ${PR_GIT_SHORT_COMMIT} ) && \ | |
( git log --patch -n1 Earthfile | grep -q "^[+-]ARG.*global.*KERI_DOCKER" ) && \ | |
echo idw-witness | |
)" | |
DOCKER_IMAGES_TARGETS="$DOCKER_IMAGES_TARGETS $( \ | |
( git log --pretty=format:'%h' -n 1 services/credential-server | grep -q ${PR_GIT_SHORT_COMMIT} ) && \ | |
echo cred-issuance | |
)" | |
DOCKER_IMAGES_TARGETS="$DOCKER_IMAGES_TARGETS $( \ | |
( git log --pretty=format:'%h' -n 1 services/credential-server-ui | grep -q ${PR_GIT_SHORT_COMMIT} ) && \ | |
echo cred-issuance-ui | |
)" | |
DOCKER_IMAGES_TARGETS="$DOCKER_IMAGES_TARGETS $( \ | |
( git log --pretty=format:'%h' -n 1 services/cip45-sample-dapp | grep -q ${PR_GIT_SHORT_COMMIT} ) && \ | |
echo cip45-sample-dapp | |
)" | |
set -e | |
STRIPPED_DOCKER_IMAGES_TARGETS=$(echo $DOCKER_IMAGES_TARGETS | tr -s ' ' | sed -e 's|^ ||' -e 's| $||') | |
if [ ! -z "${STRIPPED_DOCKER_IMAGES_TARGETS}" ]; then | |
echo "DOCKER_IMAGES_TARGETS=${STRIPPED_DOCKER_IMAGES_TARGETS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
echo "DOCKER_IMAGES_TARGETS_$(echo ${{ matrix.platform }} | sed 's|/|_|g')=${STRIPPED_DOCKER_IMAGES_TARGETS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
fi | |
git checkout ${GIT_SHORT_COMMIT} | |
fi | |
- name: 🌍 earthly (docker build and push) | |
run: | | |
set -x | |
# For PR builds, we skip any earthly build if there are no changes on any known target-related file, for branch builds, we just build everything | |
if [ ${{github.event_name}} == "pull_request" ] | |
then | |
if [ ! -z "${DOCKER_IMAGES_TARGETS}" ] | |
then | |
earthly --platform=${{ matrix.platform }} \ | |
+docker-publish \ | |
--PUSH=true \ | |
--TARGET_PLATFORM="${{ matrix.platform }}" \ | |
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \ | |
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}" \ | |
--DOCKER_IMAGES_LABELS="${DOCKER_METADATA_OUTPUT_LABELS_COMMA_SEPARATED}" \ | |
--DOCKER_IMAGES_TARGETS="${DOCKER_IMAGES_TARGETS}" | |
else | |
echo "[+] No changes on any known target-related file, skipping earthly build..." | |
fi | |
else | |
# if the workflow was triggered manually, we force the build | |
if [ ${{github.event_name}} == "workflow_dispatch" ] | |
then | |
FORCE_BUILD="--FORCE_BUILD=true" | |
DOCKER_IMAGES_TARGETS_ARG="--DOCKER_IMAGES_TARGETS=${DOCKER_IMAGES_TARGETS}" | |
earthly --platform=${{ matrix.platform }} \ | |
+docker-publish \ | |
${FORCE_BUILD} \ | |
"${DOCKER_IMAGES_TARGETS_ARG}" \ | |
--PUSH=true \ | |
--TARGET_PLATFORM="${{ matrix.platform }}" \ | |
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \ | |
--DOCKER_IMAGES_LABELS="${DOCKER_METADATA_OUTPUT_LABELS_COMMA_SEPARATED}" \ | |
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}" | |
else | |
earthly --platform=${{ matrix.platform }} \ | |
+docker-publish \ | |
${FORCE_BUILD} \ | |
--PUSH=true \ | |
--TARGET_PLATFORM="${{ matrix.platform }}" \ | |
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \ | |
--DOCKER_IMAGES_LABELS="${DOCKER_METADATA_OUTPUT_LABELS_COMMA_SEPARATED}" \ | |
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}" | |
fi | |
fi | |
- uses: cloudposse/github-action-matrix-outputs-write@v1 | |
id: out | |
with: | |
matrix-step-name: ${{ github.job }} | |
matrix-key: ${{ matrix.platform }} | |
outputs: |- | |
DOCKER_IMAGES_TARGETS: ${{ steps.metadata.outputs.DOCKER_IMAGES_TARGETS }} | |
merge-multi-platform-manifests: | |
needs: | |
- set-matrix | |
- build-n-publish | |
permissions: | |
contents: read | |
packages: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/download-artifact@v4 | |
# Manually doing this instead of using the cloudposse/read action as it seems there is some issue with it | |
- name: read-matrix-artifacts | |
id: matrix-artifacts | |
env: | |
MATRIX_STEP_NAME: build-n-publish | |
run: | | |
DOCKER_IMAGES_TARGETS=$(find . -name ${MATRIX_STEP_NAME} -maxdepth 2 -type f | head -n1 | xargs cat | jq -r '.[].DOCKER_IMAGES_TARGETS') | |
echo DOCKER_IMAGES_TARGETS=${DOCKER_IMAGES_TARGETS} | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT" | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: ⛮ cf-gha-baseline | |
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main | |
id: cf-gha-baseline | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }} | |
PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token | |
PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} | |
HUB_DOCKER_COM_USER: ${{ secrets.HUB_DOCKER_COM_USER }} | |
HUB_DOCKER_COM_PASS: ${{ secrets.HUB_DOCKER_COM_PASS }} | |
DOCKER_REGISTRIES: "${{ secrets.DOCKER_REGISTRIES }}" | |
- name: Merge multi-platform manifests | |
run: | | |
PLATFORMS=$(echo '${{ needs.set-matrix.outputs.matrix }}' | jq -r '.platform[]' | xargs echo) | |
echo $PLATFORMS | |
echo $DOCKER_IMAGES_TARGETS | |
if [ "${DOCKER_IMAGES_TARGETS}" != "null" ] | |
then | |
DOCKER_IMAGES_TARGETS_ARG="--DOCKER_IMAGES_TARGETS=${DOCKER_IMAGES_TARGETS}" | |
earthly \ | |
+docker-manifests-merge \ | |
--DOCKER_IMAGES_TARGETS="${DOCKER_IMAGES_TARGETS}" \ | |
--PUSH=true \ | |
--PLATFORMS="${PLATFORMS}" \ | |
--DOCKER_IMAGES_TARGETS="${DOCKER_IMAGES_TARGETS}" \ | |
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \ | |
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}" | |
else | |
earthly \ | |
+docker-manifests-merge \ | |
--PUSH=true \ | |
--PLATFORMS="${PLATFORMS}" \ | |
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \ | |
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}" | |
fi | |
dispatch-build-success-event: | |
runs-on: ubuntu-latest | |
needs: | |
- merge-multi-platform-manifests | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: ⛮ cf-gha-baseline | |
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main | |
id: cf-gha-baseline | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Dispatch successful build event to private repo | |
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-dispatch-event@main | |
with: | |
EVENT_TYPE: "${{ github.event_name }}-${{ steps.cf-gha-baseline.outputs.TRIGGERING_REF }}-${{ steps.cf-gha-baseline.outputs.BRANCH_NAME }}" | |
GITHUB_TOKEN: ${{ secrets.PRIVATE_REPO_PAT }} | |
GITHUB_REPO: ${{ secrets.PRIVATE_REPO }} | |
TRIGGERING_EVENT: ${{ github.event_name }} | |
TRIGGERING_REF: ${{ steps.cf-gha-baseline.outputs.TRIGGERING_REF }} | |
TRIGGERING_BRANCH: ${{ steps.cf-gha-baseline.outputs.BRANCH_NAME }} | |
TRIGGERING_GHRUNID: ${{ github.run_id }} | |
GIT_SHORT_COMMIT: ${{ steps.cf-gha-baseline.outputs.GIT_SHORT_COMMIT }} |