Skip to content

Commit

Permalink
Refactor: Workflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveLemon committed Nov 15, 2024
1 parent 82f947c commit 83713a5
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 251 deletions.
64 changes: 0 additions & 64 deletions .github/workflows/automatic-2024-pre.yml

This file was deleted.

67 changes: 0 additions & 67 deletions .github/workflows/automatic-2024.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Check for new releases

on:
workflow_dispatch:
schedule:
- cron: '0 2 * * *'

jobs:
# Todo: matrixify this
check-2024:
runs-on: ubuntu-latest
steps:
- name: Get releases
id: get_releases
run: |
curl -s https://api.github.com/repos/tModLoader/tModLoader/releases > output.txt
PRERELEASE=$(jq -r '[.[] | select(.tag_name | contains("2024")) | select(.prerelease == true)] | max_by(.created_at) | .tag_name | sub("^v";"")' output.txt)
RELEASE=$(jq -r '[.[] | select(.tag_name | contains("2024")) | select(.prerelease == false)] | max_by(.created_at) | .tag_name | sub("^v";"")' output.txt)
echo "Latest 2024 pre-release is ${PRERELEASE}." >> "$GITHUB_STEP_SUMMARY"
echo "Latest 2024 release is ${RELEASE}." >> "$GITHUB_STEP_SUMMARY"
echo "latest_prerelease=$LATEST" >> "$GITHUB_OUTPUT"
echo "latest_release=$LATEST" >> "$GITHUB_OUTPUT"
- name: Check if version is already published
id: check_releases
run: |
PRERELEASE=$(curl -s "https://hub.docker.com/v2/repositories/passivelemon/tmodloader1.4-docker/tags/${{ steps.get_releases.outputs.latest_prerelease }}")
RELEASE=$(curl -s "https://hub.docker.com/v2/repositories/passivelemon/tmodloader1.4-docker/tags/${{ steps.get_releases.outputs.latest_release }}")
if echo "$PRERELEASE" | jq -e ".digest" > /dev/null; then
echo "Version ${{ steps.get_releases.outputs.latest_prerelease }} is already published." >> "$GITHUB_STEP_SUMMARY"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "Version ${{ steps.get_releases.outputs.latest_prerelease }} is not already published." >> "$GITHUB_STEP_SUMMARY"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
if echo "$RELEASE" | jq -e ".digest" > /dev/null; then
echo "Version ${{ steps.get_releases.outputs.latest_release }} is already published." >> "$GITHUB_STEP_SUMMARY"
echo "release=true" >> "$GITHUB_OUTPUT"
else
echo "Version ${{ steps.get_releases.outputs.latest_release }} is not already published." >> "$GITHUB_STEP_SUMMARY"
echo "release=false" >> "$GITHUB_OUTPUT"
fi
- name: Run Publish workflow (Pre-release)
uses: passivelemon/PassiveLemon/.github/workflows/publish.yml@master
if: ${{ steps.check_releases.outputs.prerelease == true }}
with:
VERSION: ${{ steps.get_releases.outputs.latest_prerelease }}
PRERELEASE: true

- name: Run Publish workflow (Release)
uses: passivelemon/PassiveLemon/.github/workflows/publish.yml@master
if: ${{ steps.check_releases.outputs.release == true }}
with:
VERSION: ${{ steps.get_releases.outputs.latest_release }}
PRELRELEASE: false

59 changes: 0 additions & 59 deletions .github/workflows/manual-2024-pre.yml

This file was deleted.

61 changes: 0 additions & 61 deletions .github/workflows/manual-2024.yml

This file was deleted.

79 changes: 79 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build and push Docker image

on:
workflow_dispatch:
inputs:
VERSION:
description: 'tModLoader version'
required: true
type: string
PRERELEASE:
description: 'If the release is a pre-release'
required: true
type: boolean
secrets:
DOCKER_PASSWORD:
required: true
GHCR_PASSWORD:
required: true

jobs:
setup-build-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
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: Login to Docker Hub
uses: docker/login-action@v3
with:
username: passivelemon
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PASSWORD }}

- name: Build and push Docker image (Pre-release)
uses: docker/build-push-action@v6
if: ${{ github.event.inputs.PRERELEASE == true }}
with:
context: .
push: true
platforms: linux/amd64
build-args: VERSION=${{ github.event.inputs.VERSION }}
tags: |
passivelemon/tmodloader1.4-docker:latest-2024-pre
passivelemon/tmodloader1.4-docker:${{ github.event.inputs.VERSION }}
ghcr.io/passivelemon/tmodloader1.4-docker:latest-2024-pre
ghcr.io/passivelemon/tmodloader1.4-docker:${{ github.event.inputs.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build and push Docker image (Release)
uses: docker/build-push-action@v6
if: ${{ github.event.inputs.PRERELEASE == false }}
with:
context: .
push: true
platforms: linux/amd64
build-args: VERSION=${{ github.event.inputs.VERSION }}
tags: |
passivelemon/tmodloader1.4-docker:latest
passivelemon/tmodloader1.4-docker:latest-2024
passivelemon/tmodloader1.4-docker:${{ github.event.inputs.VERSION }}
ghcr.io/passivelemon/tmodloader1.4-docker:latest
ghcr.io/passivelemon/tmodloader1.4-docker:latest-2024
ghcr.io/passivelemon/tmodloader1.4-docker:${{ github.event.inputs.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit 83713a5

Please sign in to comment.