CI: Enable tagging with latest based on user input (#174)

This commit is contained in:
Adriano Orioli
2025-03-18 17:55:09 +01:00
committed by GitHub
parent f0c298633b
commit 4fbd34566a

View File

@@ -11,6 +11,10 @@ on:
type: string type: string
default: "stable" default: "stable"
required: true required: true
set_latest:
description: 'Tag as latest'
type: boolean
default: false
env: env:
IMAGE_NAME: godot-ci IMAGE_NAME: godot-ci
jobs: jobs:
@@ -33,13 +37,58 @@ jobs:
else else
echo "dotnet_version=mcr.microsoft.com/dotnet/sdk:8.0-jammy" >> $GITHUB_OUTPUT echo "dotnet_version=mcr.microsoft.com/dotnet/sdk:8.0-jammy" >> $GITHUB_OUTPUT
fi fi
get_tags:
name: Get Tags
runs-on: ubuntu-22.04
outputs:
tags: ${{steps.write_tags.outputs.tags}}
tags_mono: ${{steps.write_tags_mono.outputs.tags}}
steps:
- run: echo IMAGE_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- run: echo IMAGE_TAG=$(echo ${{ github.event.inputs.release_name != 'stable' && format('.{0}', github.event.inputs.release_name) || '' }}) >> $GITHUB_ENV
- name: Set tags
run: |
echo "ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}${{ env.IMAGE_TAG }}" >> tags.txt
echo "${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}${{ env.IMAGE_TAG }}" >> tags.txt
- name: Set latest tags
if: ${{inputs.set_latest}}
run: |
echo "ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:latest" >> tags.txt
echo "${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest" >> tags.txt
- name: Set Mono tags
run: |
echo "ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:mono-${{ github.event.inputs.version }}${{ env.IMAGE_TAG }}" >> tags_mono.txt
echo "${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:mono-${{ github.event.inputs.version }}${{ env.IMAGE_TAG }}" >> tags_mono.txt
- name: Set Mono latest tags
if: ${{inputs.set_latest}}
run: |
echo "ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:mono-latest" >> tags_mono.txt
echo "${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:mono-latest" >> tags_mono.txt
- uses: actions/upload-artifact@v4
with:
name: image_tags
path: tags.txt
retention-days: 1
- uses: actions/upload-artifact@v4
with:
name: image_tags_mono
path: tags_mono.txt
retention-days: 1
build: build:
name: Build Image name: Build Image
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
needs: get_tags
steps: steps:
- uses: actions/download-artifact@v4
with:
name: image_tags
- run: |
{
echo 'TAGS<<EOF'
cat tags.txt
echo EOF
} >> "$GITHUB_ENV"
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- run: echo IMAGE_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@v1.14.1 uses: docker/login-action@v1.14.1
with: with:
@@ -51,16 +100,13 @@ jobs:
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- run: echo IMAGE_TAG=$(echo ${{ github.event.inputs.release_name != 'stable' && format('.{0}', github.event.inputs.release_name) || '' }}) >> $GITHUB_ENV
- name: Build and push Docker images - name: Build and push Docker images
uses: docker/build-push-action@v2.9.0 uses: docker/build-push-action@v2.9.0
with: with:
context: . context: .
file: Dockerfile file: Dockerfile
push: true push: true
tags: | tags: ${{ env.TAGS }}
ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}${{ env.IMAGE_TAG }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.version }}${{ env.IMAGE_TAG }}
build-args: | build-args: |
GODOT_VERSION=${{ github.event.inputs.version }} GODOT_VERSION=${{ github.event.inputs.version }}
RELEASE_NAME=${{ github.event.inputs.release_name }} RELEASE_NAME=${{ github.event.inputs.release_name }}
@@ -70,10 +116,18 @@ jobs:
build-mono: build-mono:
name: Build Mono Image name: Build Mono Image
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
needs: [version] needs: [version, get_tags]
steps: steps:
- uses: actions/download-artifact@v4
with:
name: image_tags_mono
- run: |
{
echo 'TAGS<<EOF'
cat tags_mono.txt
echo EOF
} >> "$GITHUB_ENV"
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- run: echo IMAGE_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@v1.14.1 uses: docker/login-action@v1.14.1
with: with:
@@ -85,16 +139,13 @@ jobs:
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- run: echo IMAGE_TAG=$(echo ${{ github.event.inputs.release_name != 'stable' && format('.{0}', github.event.inputs.release_name) || '' }}) >> $GITHUB_ENV
- name: Build and push Docker images - name: Build and push Docker images
uses: docker/build-push-action@v2.9.0 uses: docker/build-push-action@v2.9.0
with: with:
context: . context: .
file: mono.Dockerfile file: mono.Dockerfile
push: true push: true
tags: | tags: ${{ env.TAGS }}
ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:mono-${{ github.event.inputs.version }}${{ env.IMAGE_TAG }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:mono-${{ github.event.inputs.version }}${{ env.IMAGE_TAG }}
build-args: | build-args: |
IMAGE=${{ needs.version.outputs.dotnet_version }} IMAGE=${{ needs.version.outputs.dotnet_version }}
GODOT_VERSION=${{ github.event.inputs.version }} GODOT_VERSION=${{ github.event.inputs.version }}