Docker Image CI #606
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: Docker Image CI | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
branches: [ main ] | |
jobs: | |
# Get list of versions | |
get_versions: | |
runs-on: ubuntu-latest | |
steps: | |
- name: get versions | |
id: get_versions | |
# yamllint disable-line rule:line-length | |
run: | | |
echo "versions=$(curl -s -H 'Accept: application/vnd.github.v3+json' https://api.github.com/repos/JGRennison/OpenTTD-patches/releases | jq -cMr '[.[:10]|.[]|.tag_name|.[6:]]')" >> $GITHUB_OUTPUT | |
echo "latest=$(curl -s -H 'Accept: application/vnd.github.v3+json' https://api.github.com/repos/JGRennison/OpenTTD-patches/releases | jq -cMr '([.[]|select(all(.tag_name; contains("beta")|not))])|.[:1]|.[].tag_name|.[6:]')" >> $GITHUB_OUTPUT | |
- name: Output version string | |
run: | | |
echo ${{ steps.get_versions.outputs.versions }} | |
echo ${{ steps.get_versions.outputs.latest }} | |
outputs: | |
versions: ${{ steps.get_versions.outputs.versions }} | |
latest: ${{ steps.get_versions.outputs.latest }} | |
# Build openttd images | |
build: | |
runs-on: ubuntu-latest | |
needs: get_versions | |
strategy: | |
fail-fast: false | |
matrix: | |
version: ${{ fromJson(needs.get_versions.outputs.versions) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build without push ${{ matrix.version }} with latest tag | |
if: ${{ github.ref_name != 'main' && needs.get_versions.outputs.latest == matrix.version }} | |
uses: docker/build-push-action@v5 | |
with: | |
push: false | |
pull: true | |
build-args: PATCH_VERSION=${{ matrix.version }} | |
- name: Build without push ${{ matrix.version }} | |
if: ${{ github.ref_name != 'main' && needs.get_versions.outputs.latest != matrix.version }} | |
uses: docker/build-push-action@v5 | |
with: | |
push: false | |
pull: true | |
build-args: PATCH_VERSION=${{ matrix.version }} | |
- name: Login to GCR | |
uses: docker/login-action@v3 | |
if: ${{ github.ref_name == 'main' }} | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Output platforms | |
if: ${{ github.ref_name == 'main' }} | |
run: | | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
- name: Build and push ${{ matrix.version }} with latest tag | |
if: ${{ github.ref_name == 'main' && needs.get_versions.outputs.latest == matrix.version }} | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
pull: true | |
build-args: PATCH_VERSION=${{ matrix.version }} | |
tags: | | |
ghcr.io/${{ github.repository }}:latest | |
ghcr.io/${{ github.repository }}:${{ matrix.version }} | |
- name: Build and push ${{ matrix.version }} | |
if: ${{ github.ref_name == 'main' && needs.get_versions.outputs.latest != matrix.version }} | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
pull: true | |
build-args: PATCH_VERSION=${{ matrix.version }} | |
tags: ghcr.io/${{ github.repository }}:${{ matrix.version }} | |
# Trivy test | |
- name: Run Trivy vulnerability scanner | |
if: ${{ github.ref_name == 'main' }} | |
uses: aquasecurity/trivy-action@master | |
id: trivy | |
with: | |
image-ref: 'ghcr.io/${{ github.repository }}:${{ matrix.version }}' | |
format: 'json' | |
exit-code: '0' | |
ignore-unfixed: true | |
vuln-type: 'os,library' | |
severity: 'CRITICAL,HIGH' | |
output: results.json | |
- name: test outputs | |
if: ${{ github.ref_name == 'main' }} | |
run: | | |
cat results.json |