Skip to content

Commit

Permalink
ci(#49):
Browse files Browse the repository at this point in the history
ci(#49): refactor build workflow

it is now a reusable workflow that can be included into other workflows.
two were added: one workflow for PRs, and a second for protected
branches / tags

Signed-off-by: Bryant Finney <[email protected]>
  • Loading branch information
bryant-finney committed Oct 28, 2023
1 parent 4669c65 commit a359f74
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 19 deletions.
20 changes: 1 addition & 19 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,8 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: 🐳 Docker

# run this workflow for...
# - each push to `main`
# - each release tag (starting with `v`)
# - each pull request that changes a relevant file
on:
push:
tags: v*
branches:
- main

pull_request:
paths:
- .github/workflows/docker-build.yml
- Dockerfile
- docker-compose.yml
- platforms.yml
- poetry.lock
workflow_call:

# ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Expand All @@ -33,9 +18,6 @@ jobs:
CI_REGISTRY_IMAGE: ghcr.io/${{ github.repository }}
PYTHON_VERSION: "3.11"

permissions:
packages: write

runs-on: ubuntu-latest

steps:
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Summary: define a CI/CD pipelines to run on PRs
name: ⬅️ PR Checks

on:
pull_request:
paths:
- .github/workflows/docker-build.yml
- Dockerfile
- docker-compose.yml
- platforms.yml
- poetry.lock

jobs:
changes:
# identify types of files that have changed in this PR

name: πŸ”Ž Check for changes
env:
# these types of files should all impact image builds
DOCKER_FILES: |-
.github/workflows/docker-build.yml
Dockerfile
docker-compose.yml
platforms.yml
poetry.lock
TYPES_DIR: /tmp/types

outputs:
docker: ${{ steps.compare.outputs.docker }}

runs-on: ubuntu-latest
steps:
- name: πŸ“‚ Checkout
uses: actions/checkout@v2

- name: πŸ“ Setup
run: |
mkdir -p $TYPES_DIR
printf "%s\n" "${{ env.DOCKER_FILES }}" | sort >$TYPES_DIR/docker-files.txt
- name: πŸ“ List changes
env:
GH_TOKEN: ${{ github.token }}
run: gh pr diff --name-only ${{ github.event.number }} | sort >/tmp/changes.txt

- name: ❔ Compare
id: compare
run: |
for type_path in $TYPES_DIR/*.txt; do
type_name="$(basename "$type_path" | rev | cut -d- -f2- | rev)"
comm -12 $type_path /tmp/changes.txt | xargs -I{} test -z "{}" ||
echo "${type_name}=true" >>"$GITHUB_OUTPUT"
done
call-docker-build:
if: needs.changes.outputs.docker == 'true'
needs: changes

permissions:
packages: write

uses: ./.github/workflows/docker-build.yml
13 changes: 13 additions & 0 deletions .github/workflows/protected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Summary: define a CI/CD pipeline to run on protected refs
on:
push:
tags: v*
branches:
- main

jobs:
call-docker-build:
permissions:
packages: write

uses: ./.github/workflows/docker-build.yml

0 comments on commit a359f74

Please sign in to comment.