Skip to content

chore(deps): update tj-actions/changed-files digest to 4edd678 (#55) #172

chore(deps): update tj-actions/changed-files digest to 4edd678 (#55)

chore(deps): update tj-actions/changed-files digest to 4edd678 (#55) #172

name: Build & Publish Docker Images
on:
push:
branches: [ 'main' ]
pull_request:
env:
REGISTRY: ghcr.io
NAMESPACED_REGISTRY: ghcr.io/apollographql/ci-utility-docker-images
jobs:
calculate-images-to-build:
name: Calculate Images To Build
runs-on: ubuntu-latest
outputs:
changed_dirs: ${{ steps.filter_config_directories.outputs.changed_dirs }}
steps:
- name: "Checkout repository"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: "Calculate changed files directories"
id: calculate_changed_files
uses: tj-actions/changed-files@4edd678ac3f81e2dc578756871e4d00c19191daf
with:
dir_names: true
dir_names_exclude_current_dir: true
json: true
- name: "Filter out config directories"
id: filter_config_directories
run: |
CHANGED_DIRS=$(echo "${{ steps.calculate_changed_files.outputs.all_changed_files }}" | jq -c '[.[] | select(. | contains(".") | not)'])
echo "changed_dirs=$CHANGED_DIRS" >> "$GITHUB_OUTPUT"
build-and-push-images:
name: Build and Push Docker Image
if: ${{ needs.calculate-images-to-build.outputs.changed_dirs != '' && toJson(fromJson(needs.calculate-images-to-build.outputs.changed_dirs)) != '[]' }}
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
attestations: write
id-token: write
needs:
- calculate-images-to-build
strategy:
matrix:
changed_dir: ${{ fromJSON(needs.calculate-images-to-build.outputs.changed_dirs ) }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Log in to the Container Registry
uses: docker/login-action@06895751d15a223ec091bea144ad5c7f50d228d0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Details From config.yml
id: extract_from_config_yaml
run: |
echo "desired_version=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.version')" >> "$GITHUB_OUTPUT"
echo "platforms=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.platforms | join(",")')" >> "$GITHUB_OUTPUT"
echo "description=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.description')" >> "$GITHUB_OUTPUT"
- name: Check Image to Build Does Not Already Exist
run: |
if docker manifest inspect ${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}:${{ steps.extract_from_config_yaml.outputs.desired_version }} > /dev/null; then
echo "The tag "${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}:${{ steps.extract_from_config_yaml.outputs.desired_version }}" already exists in the repository. Do you need to bump the version in the config.yml?"
exit 1
fi
- name: Calculate Version
id: calculate_version
run: |
VERSION=${{ github.event_name == 'pull_request' && format('{0}-PR{1}.{2}', steps.extract_from_config_yaml.outputs.desired_version, github.event.number, github.event.pull_request.head.sha) || steps.extract_from_config_yaml.outputs.desired_version}}
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@0f069ddc17b8eb78586b08a7fe335fd54649e2d3
- name: Get Docker Metadata
id: meta
uses: docker/metadata-action@0de3687b53cd804b63dd87819f7bda043569ce4a
env:
DOCKER_METADATA_PR_HEAD_SHA: true
with:
images: ${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}
tags: |
type=semver,pattern={{version}},value=v${{ steps.calculate_version.outputs.version }}
type=sha,prefix=
labels: |
org.opencontainers.image.title=${{ matrix.changed_dir }}
org.opencontainers.image.description=${{ steps.extract_from_config_yaml.outputs.description }}
org.opencontainers.image.vendor=Apollo GraphQL
org.opencontainers.image.licenses=MIT
annotations: |
org.opencontainers.image.title=${{ matrix.changed_dir }}
org.opencontainers.image.description=${{ steps.extract_from_config_yaml.outputs.description }}
org.opencontainers.image.vendor=Apollo GraphQL
org.opencontainers.image.licenses=MIT
- name: Build and Push Docker image
id: push
uses: docker/build-push-action@5e99dacf67635c4f273e532b9266ddb609b3025a
with:
context: ${{ github.workspace }}/${{ matrix.changed_dir }}
file: ${{ github.workspace }}/${{ matrix.changed_dir }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
annotations: ${{ steps.meta.outputs.annotations }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ steps.extract_from_config_yaml.outputs.platforms }}
- name: Create Git Tag
uses: mathieudutour/github-tag-action@9d35d648e836d5db77936aa35a3a5c7bc16092c8
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
default_prerelease_bump: false
custom_tag: ${{ matrix.changed_dir }}/v${{ steps.calculate_version.outputs.version }}
dry_run: ${{ github.event_name == 'pull_request' }}
tag_prefix: ""
- name: Create GitHub Release
if: ${{ github.event_name != 'pull_request' }}
uses: comnoco/create-release-action@7dea6dc82ac9d97ced7a764aa82811451bba80e0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ matrix.changed_dir }}/v${{ steps.calculate_version.outputs.version }}
release_name: ${{ matrix.changed_dir }} - v${{ steps.calculate_version.outputs.version }}
check-builds-all-completes:
name: Docker Images Built & Pushed
if: ${{ always() }}
runs-on: ubuntu-latest
needs:
- build-and-push-images
steps:
- run: |
exit ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 1 || 0 }}