mirror of
https://github.com/encounter/compilers.git
synced 2026-03-30 11:04:07 -07:00
82 lines
2.8 KiB
YAML
82 lines
2.8 KiB
YAML
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@v4
|
|
|
|
- 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@v4
|
|
|
|
- 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@v4
|
|
|
|
- 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@v5
|
|
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 }}
|