Build and Push Pre-release Docker Image #945
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: Build and Push Pre-release Docker Image | |
on: | |
schedule: | |
- cron: '0 */2 * * *' # Run every 2 hours | |
workflow_dispatch: # Allow manual triggering | |
push: | |
paths-ignore: # Prevent triggering on updates to .last_dev_build | |
- '.last_build' | |
- '.last_dev_build' | |
- '.last_prerelease_build' | |
- 'dockerfile' | |
- 'dockerfile.dev' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-and-push-prerelease: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Get latest pre-release info | |
id: prerelease | |
run: | | |
PRERELEASE_INFO=$(curl -s "https://api.github.com/repos/TNTwise/REAL-Video-Enhancer/releases" | jq -r '[.[] | select(.prerelease == true)] | sort_by(.published_at) | reverse | .[0]') | |
echo "PRERELEASE_TAG=$(echo $PRERELEASE_INFO | jq -r .tag_name)" >> $GITHUB_OUTPUT | |
echo "PRERELEASE_DATE=$(echo $PRERELEASE_INFO | jq -r .published_at)" >> $GITHUB_OUTPUT | |
- name: Determine if build should proceed | |
id: check | |
run: | | |
# Define individual conditions using proper bash syntax | |
MANUAL_TRIGGER=$([[ "${{ github.event_name }}" == "workflow_dispatch" ]] && echo true || echo false) | |
NEW_COMMIT_PUSHED=$([[ "${{ github.event_name }}" == "push" && "${{ github.actor }}" != "github-actions" ]] && echo true || echo false) | |
NEW_PRERELEASE_DETECTED=$([[ ! -f .last_prerelease_build ]] || [[ "$(cat .last_prerelease_build)" != "${{ steps.prerelease.outputs.PRERELEASE_TAG }}_${{ steps.prerelease.outputs.PRERELEASE_DATE }}" ]] && echo true || echo false) | |
# Check if any condition is true for proceeding with the build | |
if [[ $MANUAL_TRIGGER == "true" || $NEW_COMMIT_PUSHED == "true" || $NEW_PRERELEASE_DETECTED == "true" ]]; then | |
echo "update=true" >> $GITHUB_OUTPUT | |
else | |
echo "update=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Prepare Docker metadata | |
id: meta | |
if: steps.check.outputs.update == 'true' | |
run: | | |
echo "IMAGE_ID=$(echo ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | tr '[A-Z]' '[a-z]')" >> $GITHUB_OUTPUT | |
- name: Log in to the Container registry | |
if: steps.check.outputs.update == 'true' | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
if: steps.check.outputs.update == 'true' | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.IMAGE_ID }}:pre-release | |
file: ./dockerfile.pre | |
- name: Update last build info | |
if: steps.check.outputs.update == 'true' | |
run: | | |
# Function to update .last_prerelease_build | |
update_last_build_file() { | |
echo "$1" > .last_prerelease_build | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add .last_prerelease_build | |
git commit -m "Update last pre-release build info" | |
git push | |
} | |
# Combine tag and date for the last build info | |
PRE_RELEASE_TAG_DATE="${{ steps.prerelease.outputs.PRERELEASE_TAG }}_${{ steps.prerelease.outputs.PRERELEASE_DATE }}" | |
if [[ -f .last_prerelease_build ]]; then | |
OLD_PRERELEASE=$(cat .last_prerelease_build) | |
if [[ "$PRE_RELEASE_TAG_DATE" != "$OLD_PRERELEASE" ]]; then | |
update_last_build_file "$PRE_RELEASE_TAG_DATE" | |
else | |
echo "No new pre-release, skipping the commit step." | |
fi | |
else | |
update_last_build_file "$PRE_RELEASE_TAG_DATE" | |
fi |