generated from bcgov/platform-services-template
-
Notifications
You must be signed in to change notification settings - Fork 3
73 lines (65 loc) · 2.09 KB
/
pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Pull Request Pipeline
on:
pull_request:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-fluent-bit
BUILD_PATH: podman/fluent-bit
jobs:
# https://github.community/t/run-job-only-if-folder-changed/118292
build-checks:
outputs:
build: ${{ steps.check.outputs.build }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# https://github.com/actions/checkout
fetch-depth: 2
- name: Check and process modified files
id: check
run: |
# Check git diff against build path
while read -r filename
do
if [[ $filename == ${{ env.BUILD_PATH }}/* ]]
then
echo "$filename --> triggering build"
echo "::set-output name=build::true"
break
fi
done < <(git diff --name-only)
build-and-push-image:
needs: build-checks
if: needs.build-checks.outputs.build == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
# https://github.com/marketplace/actions/docker-login#github-container-registry
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/marketplace/actions/docker-metadata-action
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# https://github.com/marketplace/actions/build-and-push-docker-images
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: ${{ env.BUILD_PATH }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}