Skip to content

Commit

Permalink
Experimental: Get version in separate build phase
Browse files Browse the repository at this point in the history
  • Loading branch information
duckfullstop committed Jan 18, 2025
1 parent 8bf78c6 commit 5b42355
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@ on:
- cron: '0 3 * * *'

jobs:
cri:
get-upstream-versions:
strategy:
matrix:
train:
- stable
- testing
arch:
- os: ubuntu-24.04
name: linux/amd64
label: linux-amd64
- os: ubuntu-24.04-arm
name: linux/arm64
label: linux-arm64
runs-on: ${{ matrix.arch.os }}
steps:

- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: '0'

- name: Discover upstream version
uses: ropenttd/cdn_version_scraper@master
with:
Expand All @@ -42,14 +29,42 @@ jobs:
- name: Dump upstream train version to file
shell: bash
run: |
echo $GITHUB_OUTPUT > version.txt
cat $GITHUB_OUTPUT > version.txt
- name: Upload upstream train version information
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ver-${{ matrix.train }}
path: version.txt
retention-days: 1
overwrite: true
cri:
strategy:
matrix:
train:
- stable
- testing
arch:
- os: ubuntu-24.04
name: linux/amd64
label: linux-amd64
- os: ubuntu-24.04-arm
name: linux/arm64
label: linux-arm64
runs-on: ${{ matrix.arch.os }}
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: '0'

- name: Get target version for this train from version phase
uses: actions/download-artifact@v4
with:
name: ver-${{ matrix.train }}

- name: Set target version environment variable
run: cat version.txt >> $GITHUB_ENV

- name: Generate CRI metadata
id: meta
uses: docker/metadata-action@v4
Expand All @@ -63,34 +78,34 @@ jobs:
org.opencontainers.image.url=https://github.com/ropenttd/docker_openttd
org.opencontainers.image.source=https://github.com/openttd/openttd
org.opencontainers.image.vendor=Reddit OpenTTD
org.opencontainers.image.version=${{ steps.version.outputs.version }}
org.opencontainers.image.version=${{ env.version }}
tags: |
${{ steps.version.outputs.version }}-${{ matrix.arch.label }}
${{ env.version }}-${{ matrix.arch.label }}
- name: Set up Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to GHCI
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
build-args: |
OPENTTD_VERSION=${{ steps.version.outputs.version }}
OPENTTD_VERSION=${{ env.version }}
platforms: ${{ matrix.arch.name }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
Expand Down Expand Up @@ -125,7 +140,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get target version for this train from build phase
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ver-${{ matrix.train }}

Expand All @@ -152,7 +167,7 @@ jobs:
uses: Noelware/docker-manifest-action@0.4.2
if: matrix.train == 'stable' && matrix.container_store == 'docker'
with:
inputs: ${{env.DOCKER_REPO}}:latest,${{env.DOCKER_REPO}}:stable,${{env.DOCKER_REPO}}:${{env.version}},${{env.DOCKER_REPO}}:${{ steps.version.outputs.semver_major }}
inputs: ${{env.DOCKER_REPO}}:latest,${{env.DOCKER_REPO}}:stable,${{env.DOCKER_REPO}}:${{env.version}},${{env.DOCKER_REPO}}:${{ env.semver_major }}
images: ${{env.DOCKER_REPO}}:${{env.version}}-linux-amd64,${{env.DOCKER_REPO}}:${{env.version}}-linux-arm64
push: true

Expand Down

0 comments on commit 5b42355

Please sign in to comment.