Skip to content

Commit d108b88

Browse files
Adding new GitHub Actions Workflows (#116)
* Add first attempt at new GHA workflows * Make sure mmv is installed * Extract more to re-usable workflows
1 parent b6f6f2a commit d108b88

File tree

6 files changed

+271
-40
lines changed

6 files changed

+271
-40
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: "Build Docker Image"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
directory:
7+
type: string
8+
description: "The folder that contains the Dockerfile and all that's needed to build the image"
9+
required: true
10+
image_name:
11+
type: string
12+
description: "The name of the image to build"
13+
required: true
14+
image_registry:
15+
type: string
16+
description: "The registry the image should be pushed to"
17+
required: true
18+
description:
19+
type: string
20+
description: "A description of the image being built"
21+
required: true
22+
tags:
23+
type: string
24+
description: "A multi-line string that can be passed to the docker/metadata-action"
25+
required: true
26+
platforms:
27+
type: string
28+
description: "A comma separated list of the platforms to build for"
29+
required: true
30+
31+
jobs:
32+
build_docker_image:
33+
name: Build Docker Image (${{ inputs.image_name }})
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: "Checkout repository"
37+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@941183f0a080fa6be59a9e3d3f4108c19a528204
40+
- name: Get Docker Metadata
41+
id: meta
42+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804
43+
env:
44+
DOCKER_METADATA_PR_HEAD_SHA: true
45+
with:
46+
images: ${{ inputs.image_registry }}/${{ inputs.image_name }}
47+
tags: ${{ inputs.tags }}
48+
labels: |
49+
org.opencontainers.image.title=${{ inputs.image_name }}
50+
org.opencontainers.image.description=${{ inputs.description }}
51+
org.opencontainers.image.vendor=Apollo GraphQL
52+
org.opencontainers.image.licenses=MIT
53+
annotations: |
54+
org.opencontainers.image.title=${{ inputs.image_name }}
55+
org.opencontainers.image.description=${{ inputs.description }}
56+
org.opencontainers.image.vendor=Apollo GraphQL
57+
org.opencontainers.image.licenses=MIT
58+
- name: Build and Push Docker image
59+
id: push
60+
uses: docker/build-push-action@67dc78bbaf388b3265f7e1c880e681f4b90d5f48
61+
with:
62+
context: ${{ inputs.directory }}
63+
file: ${{ inputs.directory }}/Dockerfile
64+
push: true
65+
tags: ${{ steps.meta.outputs.tags }}
66+
annotations: ${{ steps.meta.outputs.annotations }}
67+
labels: ${{ steps.meta.outputs.labels }}
68+
platforms: ${{ inputs.platforms }}

.github/workflows/docker_publish.yml

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build & Publish Docker Images
1+
name: Build & Publish Changed Docker Images
22

33
on:
44
push:
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
2020
- name: "Calculate changed files directories"
2121
id: calculate_changed_files
22-
uses: tj-actions/changed-files@5426ecc3f5c2b10effaefbd374f0abdc6a571b2f
22+
uses: tj-actions/changed-files@c34c1c13a740b06851baff92ab9a653d93ad6ce7
2323
with:
2424
dir_names: true
2525
dir_names_exclude_current_dir: true
@@ -47,61 +47,38 @@ jobs:
4747
- name: Checkout repository
4848
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
4949
- name: Log in to the Container Registry
50-
uses: docker/login-action@6d4b68b490aef8836e8fb5e50ee7b3bdfa5894f0
50+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
5151
with:
5252
registry: ${{ env.REGISTRY }}
5353
username: ${{ github.actor }}
5454
password: ${{ secrets.GITHUB_TOKEN }}
5555
- name: Extract Details From config.yml
5656
id: extract_from_config_yaml
57-
run: |
58-
echo "desired_version=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.version')" >> "$GITHUB_OUTPUT"
59-
echo "platforms=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.platforms | join(",")')" >> "$GITHUB_OUTPUT"
60-
echo "description=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.description')" >> "$GITHUB_OUTPUT"
57+
uses: ./.github/workflows/extract_details_from_config.yml
58+
with:
59+
config_yaml_path: ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yaml
6160
- name: Check Image to Build Does Not Already Exist
6261
run: |
63-
if docker manifest inspect ${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}:${{ steps.extract_from_config_yaml.outputs.desired_version }} > /dev/null; then
64-
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?"
62+
if docker manifest inspect ${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}:${{ steps.extract_from_config_yaml.outputs.current_version }} > /dev/null; then
63+
echo "The tag "${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}:${{ steps.extract_from_config_yaml.outputs.current_version }}" already exists in the repository. Do you need to bump the version in the config.yml?"
6564
exit 1
6665
fi
6766
- name: Calculate Version
6867
id: calculate_version
6968
run: |
70-
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}}
69+
VERSION=${{ github.event_name == 'pull_request' && format('{0}-PR{1}.{2}', steps.extract_from_config_yaml.outputs.current_version, github.event.number, github.event.pull_request.head.sha) || steps.extract_from_config_yaml.outputs.current_version}}
7170
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
72-
- name: Set up Docker Buildx
73-
uses: docker/setup-buildx-action@e600775e527acba2317260cadb64b7e19efd5362
74-
- name: Get Docker Metadata
75-
id: meta
76-
uses: docker/metadata-action@418e4b98bf2841bd337d0b24fe63cb36dc8afa55
77-
env:
78-
DOCKER_METADATA_PR_HEAD_SHA: true
71+
- name: Build Docker Image (${{ matrix.changed_dir }})
72+
uses: ./.github/workflows/build_docker_image.yml
7973
with:
80-
images: ${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}
74+
description: ${{ steps.extract_from_config_yaml.outputs.description }}
75+
directory: ${{ github.workspace }}/${{ matrix.changed_dir }}
76+
image_name: ${{ matrix.changed_dir }}
77+
image_registry: ${{ env.NAMESPACED_REGISTRY }}
78+
platforms: ${{ steps.extract_from_config_yaml.outputs.platforms }}
8179
tags: |
82-
type=semver,pattern={{version}},value=v${{ steps.calculate_version.outputs.version }}
80+
type=semver,pattern={{version}},value=v${{ inputs.version }}
8381
type=sha,prefix=
84-
labels: |
85-
org.opencontainers.image.title=${{ matrix.changed_dir }}
86-
org.opencontainers.image.description=${{ steps.extract_from_config_yaml.outputs.description }}
87-
org.opencontainers.image.vendor=Apollo GraphQL
88-
org.opencontainers.image.licenses=MIT
89-
annotations: |
90-
org.opencontainers.image.title=${{ matrix.changed_dir }}
91-
org.opencontainers.image.description=${{ steps.extract_from_config_yaml.outputs.description }}
92-
org.opencontainers.image.vendor=Apollo GraphQL
93-
org.opencontainers.image.licenses=MIT
94-
- name: Build and Push Docker image
95-
id: push
96-
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1
97-
with:
98-
context: ${{ github.workspace }}/${{ matrix.changed_dir }}
99-
file: ${{ github.workspace }}/${{ matrix.changed_dir }}/Dockerfile
100-
push: true
101-
tags: ${{ steps.meta.outputs.tags }}
102-
annotations: ${{ steps.meta.outputs.annotations }}
103-
labels: ${{ steps.meta.outputs.labels }}
104-
platforms: ${{ steps.extract_from_config_yaml.outputs.platforms }}
10582
- name: Create Git Tag
10683
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b
10784
with:
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Build & Publish Docker Images - Daily
2+
3+
on:
4+
schedule:
5+
- cron: "0 10 * * *" # Run this job every day at 10am to get a daily build
6+
workflow_dispatch: { }
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
NAMESPACED_REGISTRY: ghcr.io/apollographql/ci-utility-docker-images
11+
12+
jobs:
13+
find-all-docker-images:
14+
uses: ./.github/workflows/find_all_docker_images.yml
15+
build-and-push-images:
16+
name: Build and Push Docker Image
17+
needs: find-all-docker-images
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
packages: write
22+
attestations: write
23+
id-token: write
24+
strategy:
25+
matrix:
26+
image_directory: ${{ fromJSON(needs.find-all-docker-images.outputs.docker_images) }}
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
30+
- name: Get current date
31+
id: get-date
32+
run: echo "date=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
33+
- name: Log in to the Container Registry
34+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
- name: Extract Details From config.yml
40+
id: extract_from_config_yaml
41+
uses: ./.github/workflows/extract_details_from_config.yml
42+
with:
43+
config_yaml_path: ${{ github.workspace }}/${{ matrix.image_directory }}/config.yaml
44+
- name: Build Docker Image
45+
uses: ./.github/workflows/build_docker_image.yml
46+
with:
47+
description: ${{ steps.extract_from_config_yaml.outputs.description }}
48+
directory: ${{ github.workspace }}/${{ matrix.image_directory }}
49+
image_name: ${{ matrix.image_directory }}
50+
image_registry: ${{ env.NAMESPACED_REGISTRY }}
51+
platforms: ${{ steps.extract_from_config_yaml.outputs.platforms }}
52+
tags: |
53+
type=semver,pattern={{version}},value=v${{ steps.extract_from_config_yaml.outputs.current_version }}-${{ steps.get-date.outputs.date }}
54+
55+
check-builds-all-completes:
56+
name: Docker Images Built & Pushed
57+
if: ${{ always() }}
58+
runs-on: ubuntu-latest
59+
needs:
60+
- build-and-push-images
61+
steps:
62+
- run: |
63+
exit ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 1 || 0 }}
64+
65+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
config_yaml_path:
5+
type: string
6+
required: true
7+
description: "The path to the config.yaml file in the repo"
8+
outputs:
9+
current_version: ${{ steps.extract_from_config_yaml.outputs.current_version }}
10+
platforms: ${{ steps.extract_from_config_yaml.outputs.platforms }}
11+
description: ${{ steps.extract_from_config_yaml.outputs.description }}
12+
13+
jobs:
14+
15+
extract_details_from_config_yaml:
16+
name: "Extract Details From config.yaml"
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: "Checkout repository"
20+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
21+
- name: Extract Details From config.yml
22+
id: extract_from_config_yaml
23+
run: |
24+
echo "current_version=$(cat ${{ inputs.config_yaml_path }} | yq '.version')" >> "$GITHUB_OUTPUT"
25+
echo "platforms=$(cat ${{ inputs.config_yaml_path }} | yq '.platforms | join(",")')" >> "$GITHUB_OUTPUT"
26+
echo "description=$(cat ${{ inputs.config_yaml_path }} | yq '.description')" >> "$GITHUB_OUTPUT"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
on:
2+
workflow_call:
3+
outputs:
4+
docker_images:
5+
description: "List of all the directories of Docker Images that need to be built"
6+
value: ${{ jobs.find-all-docker-images.outputs.folders }}
7+
8+
jobs:
9+
find-all-docker-images:
10+
name: Find All Docker Images
11+
runs-on: ubuntu-latest
12+
outputs:
13+
folders: ${{ steps.filter_config_directories.outputs.docker_images }}
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
17+
- id: find-folders
18+
uses: SuperEvilMegacorp/list-folders-action@5f9fce10cea7c4e4f094e6638e7209865af5501e
19+
with:
20+
path: ${{ github.workspace }}
21+
- name: "Filter out config directories"
22+
id: filter_config_directories
23+
run: |
24+
DOCKER_IMAGES=$(echo "${{ steps.find-folders.outputs.folders }}" | jq -c '[.[] | select(. | contains(".") | not)'])
25+
echo "docker_images=$DOCKER_IMAGES" >> "$GITHUB_OUTPUT"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Raise PR for Monthly Version Bump
2+
3+
on:
4+
schedule:
5+
- cron: '0 9 1 * *' # Run at midnight each Sunday
6+
workflow_dispatch: { }
7+
8+
jobs:
9+
find-all-docker-images:
10+
uses: ./.github/workflows/find_all_docker_images.yml
11+
create-new-config-yamls:
12+
name: "Calculate and Store New config.yaml"
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
needs: find-all-docker-images
18+
strategy:
19+
matrix:
20+
image_directory: ${{ fromJSON(needs.find-all-docker-images.outputs.docker_images ) }}
21+
steps:
22+
- name: "Checkout Repo"
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
24+
- name: Extract Details From config.yml
25+
id: extract_from_config_yaml
26+
uses: ./.github/workflows/extract_details_from_config.yml
27+
with:
28+
config_yaml_path: ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yaml
29+
- name: Bump Minor Version
30+
id: bump
31+
uses: cbrgm/semver-bump-action@main
32+
with:
33+
current-version: ${{ steps.extract_from_config_yaml.outputs.current_version }}
34+
bump-level: patch
35+
- name: "Calculate version to bump to"
36+
id: calculate-version
37+
run: |
38+
yq w ${{ github.workspace }}/${{ matrix.image_directory }}/config.yml .version ${{ steps.bump.outputs.new_version }} >> ${{ github.workspace }}/${{ matrix.image_directory }}_config.yml
39+
- name: "Store saved config.yaml"
40+
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
41+
with:
42+
name: new-version_${{ matrix.image_directory }}/config.yml
43+
path: ${{ github.workspace }}/${{ matrix.image_directory }}_config.yml
44+
45+
raise_pull_request:
46+
name: "Raise Pull Request"
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: "Checkout Repo"
50+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
51+
- name: Get current date
52+
id: get-date
53+
run: echo "date=$(date +'%Y%m%d%')" >> $GITHUB_OUTPUT
54+
- name: Download new config YAMLs
55+
id: download-new-config-yamls
56+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
57+
with:
58+
pattern: new-version_*
59+
- name: Move the configs to their new location
60+
run: |
61+
apt-get update
62+
apt-get install -y mmv
63+
mmv *_config.yaml '${{ github.workspace }}/#1/config.yaml'
64+
- name: Create Pull Request
65+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e
66+
with:
67+
commit-message: 'Update Patch Versions For All Images - ${{ steps.get-date.outputs.date }}'
68+
branch: update-patch-versions
69+
title: 'Update Patch Versions For All Images - ${{ steps.get-date.outputs.date }}'
70+
body: Automated PR to bump patch versions for all images, to ensure they don't get stale

0 commit comments

Comments
 (0)