feat: smarter workflows #138
Workflow file for this run
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: PR | |
on: | |
pull_request: | |
branches: [main] | |
concurrency: | |
# PR open and close use the same group, allowing only one at a time | |
group: pr-${{ github.workflow }}-${{ github.event.number }} | |
cancel-in-progress: true | |
jobs: | |
scrub: | |
name: Scrub for changed Dockerfiles | |
runs-on: ubuntu-22.04 | |
outputs: | |
json: ${{ steps.dockerfiles.outputs.json }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get Dockerfiles | |
id: dockerfiles | |
run: | | |
# Get all Dockerfiles that have changed | |
git fetch origin ${{ github.event.repository.default_branch }} | |
DOCKERFILES=($(git diff --name-only origin/${{ github.event.repository.default_branch }} | grep -E '^.*/.*/Dockerfile$' | sort -u)) | |
LIST=$(echo "[" | |
for d in "${DOCKERFILES[@]}"; do | |
# Clip off /Dockerfile and use the rest to handle package name and major tag | |
BASE=${d%/*} | |
VERSION=${BASE##*/} | |
PACKAGE=${BASE%/*} | |
echo "{\"package\": \"$PACKAGE\", \"major_tag\": \"$VERSION\"}," | |
done | |
echo "]" | |
) | |
# Clip extra comma and send to output | |
ONELINE=$(echo $LIST) | |
JSON=$(echo $ONELINE | sed 's/\(.*\),/\1/') | |
echo "json=${JSON}" | |
echo "json=${JSON}" >> $GITHUB_OUTPUT | |
# https://github.com/bcgov-nr/action-builder-ghcr | |
builds: | |
name: Builds | |
needs: [scrub] | |
if: "!github.event.pull_request.head.repo.fork" | |
permissions: | |
packages: write | |
runs-on: ubuntu-22.04 | |
strategy: | |
matrix: | |
include: ${{ fromJSON(needs.scrub.outputs.json) }} | |
# include: [ {"package": "bitnami/postgresql", "major_tag": "12"}, {"package": "bitnami/postgresql", "major_tag": "13"}, {"package": "bitnami/postgresql", "major_tag": "14"}, {"package": "bitnami/postgresql", "major_tag": "15"}, {"package": "bitnami/postgresql", "major_tag": "16"} ] | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get tag | |
id: tag | |
run: | | |
TAG=$(grep '^FROM' ${{ matrix.package }}/${{ matrix.major_tag }}/Dockerfile | cut -d':' -f2) | |
echo "full_tag=${TAG}" >> $GITHUB_OUTPUT | |
- name: Build or import | |
uses: bcgov-nr/action-builder-ghcr@v2.0.0 | |
with: | |
build_context: ${{ matrix.package }}/${{ matrix.major_tag }} | |
package: ${{ matrix.package }} | |
tag: ${{ steps.tag.outputs.full_tag }} | |
triggers: ${{ matrix.package}}/${{ matrix.triggers }} | |
# pr-description-add: | |
# name: PR Description Add | |
# needs: [builds] | |
# runs-on: ubuntu-22.04 | |
# permissions: | |
# pull-requests: write | |
# timeout-minutes: 1 | |
# steps: | |
# - uses: bcgov-nr/action-pr-description-add@v1.1.0 | |
# with: | |
# github_token: ${{ secrets.GITHUB_TOKEN }} | |
# add_markdown: | | |
# --- | |
# Thanks for the PR! | |
# Any new images should be viewable with [our repo packages](https://github.com/orgs/bcgov/packages?repo_name=nr-containers). :) |