-
Notifications
You must be signed in to change notification settings - Fork 5
81 lines (71 loc) · 2.79 KB
/
ci.yaml
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
74
75
76
77
78
79
80
81
name: Publish
on:
push:
branches:
- main
pull_request:
branches: [ main ]
jobs:
check_templated_files:
name: Ensure templated Dockerfiles are up to date
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Generate templates
run: python3 template.py values.yaml
- name: Fail if anything has changed
run: git diff --exit-code
create_matrix:
name: Create Matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.create-matrix.outputs.matrix }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Create list of changed files
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "Diff between origin/${{ github.event.pull_request.base.sha }} and $GITHUB_SHA"
git fetch origin ${{ github.event.pull_request.base.sha }} --depth=1
export DIFF=$( git diff --name-only ${{ github.event.pull_request.base.sha }} $GITHUB_SHA )
else
echo "Diff between ${{ github.event.before }} and $GITHUB_SHA"
git fetch origin ${{ github.event.before }} --depth=1
export DIFF=$( git diff --name-only ${{ github.event.before }} $GITHUB_SHA )
fi
echo "$DIFF" | tee changed_files.txt
- name: Create matrix of images to generate
id: create-matrix
run: |
# e.g. if we wanted to run the matrix for a set of platforms:
# echo "matrix=$(python3 matrix.py values.yaml --platforms n64 ps1 saturn)" >> $GITHUB_OUTPUT
echo "matrix=$(python3 matrix.py values.yaml --dockerfiles changed_files.txt)" >> $GITHUB_OUTPUT
run_matrix:
name: Run Matrix
permissions: write-all
runs-on: ubuntu-22.04
needs: [check_templated_files, create_matrix]
if: ${{ needs.create_matrix.outputs.matrix != '' && needs.create_matrix.outputs.matrix != '{"include":[]}' }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.create_matrix.outputs.matrix) }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push to Github registry
uses: docker/build-push-action@v4
with:
# only publish from main branch and don't publish on forks
push: ${{ github.ref == 'refs/heads/main' && ! github.event.pull_request.head.repo.fork }}
tags: ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest
file: ${{ matrix.dockerfile }}