From 7fa4d6a3d1064c1e2d479f62e6cce6009e7cc6bd Mon Sep 17 00:00:00 2001 From: KennyG Date: Mon, 30 Mar 2026 12:24:26 -0400 Subject: [PATCH] Enhance GitHub Actions workflow by adding environment variables for GHCR repository and improving image tag preparation logic. Update DockerHub sync step to conditionally use password or token. Refactor output handling for built images. --- .github/workflows/main.yml | 43 ++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ce31a92..3a6c63a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,6 +5,9 @@ on: branches: - 'master' +env: + GHCR_REPOSITORY: ghcr.io/${{ github.repository }} + jobs: quality-checks: runs-on: ubuntu-latest @@ -64,9 +67,28 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 + - + name: Prepare image tags + id: image_tags + env: + DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }} + GHCR_REPOSITORY: ${{ env.GHCR_REPOSITORY }} + DATE: ${{ steps.date.outputs.date }} + run: | + { + echo 'tags<> "$GITHUB_OUTPUT" - name: Login to DockerHub uses: docker/login-action@v4 + if: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }} with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} @@ -86,21 +108,18 @@ jobs: push: true build-args: | VERSION=${{ steps.date.outputs.date }} - tags: | - ${{ secrets.DOCKERHUB_REPOSITORY }}:latest - ${{ secrets.DOCKERHUB_REPOSITORY }}:${{ steps.date.outputs.date }} - ghcr.io/${{ github.repository }}:latest - ghcr.io/${{ github.repository }}:${{ steps.date.outputs.date }} + tags: ${{ steps.image_tags.outputs.tags }} dockerhub-sync-readme: needs: dockerhub-build-push runs-on: ubuntu-latest + if: ${{ secrets.DOCKERHUB_USERNAME != '' && (secrets.DOCKERHUB_PASSWORD != '' || secrets.DOCKERHUB_TOKEN != '') && secrets.DOCKERHUB_REPOSITORY != '' }} steps: - name: Sync README uses: docker://lsiodev/readme-sync:latest env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD != '' && secrets.DOCKERHUB_PASSWORD || secrets.DOCKERHUB_TOKEN }} GIT_REPOSITORY: ${{ github.repository }} DOCKER_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }} GIT_BRANCH: master @@ -157,7 +176,7 @@ jobs: id: release_body env: DOCKERHUB_REPO: ${{ secrets.DOCKERHUB_REPOSITORY }} - GHCR_REPO: ghcr.io/${{ github.repository }} + GHCR_REPO: ${{ env.GHCR_REPOSITORY }} DATE: ${{ steps.date.outputs.date }} HAS_COMMITS: ${{ steps.commits.outputs.has_commits }} COMMITS: ${{ steps.commits.outputs.commits }} @@ -167,10 +186,12 @@ jobs: echo '' echo 'Docker images have been built and pushed:' echo '' - echo '**Docker Hub:**' - echo "- \`${DOCKERHUB_REPO}:latest\`" - echo "- \`${DOCKERHUB_REPO}:${DATE}\`" - echo '' + if [ -n "$DOCKERHUB_REPO" ]; then + echo '**Docker Hub:**' + echo "- \`${DOCKERHUB_REPO}:latest\`" + echo "- \`${DOCKERHUB_REPO}:${DATE}\`" + echo '' + fi echo '**GitHub Container Registry:**' echo "- \`${GHCR_REPO}:latest\`" echo "- \`${GHCR_REPO}:${DATE}\`"