Refactor GitHub Actions workflow to utilize environment variables for DockerHub credentials, enhancing security and maintainability. Update conditions for DockerHub sync step to improve logic for using password or token.

This commit is contained in:
KennyG 2026-03-30 12:28:10 -04:00
parent 7fa4d6a3d1
commit 4484879651

View file

@ -53,6 +53,10 @@ jobs:
dockerhub-build-push: dockerhub-build-push:
needs: quality-checks needs: quality-checks
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }}
steps: steps:
- -
name: Get current date name: Get current date
@ -71,7 +75,7 @@ jobs:
name: Prepare image tags name: Prepare image tags
id: image_tags id: image_tags
env: env:
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }} DOCKERHUB_REPOSITORY: ${{ env.DOCKERHUB_REPOSITORY }}
GHCR_REPOSITORY: ${{ env.GHCR_REPOSITORY }} GHCR_REPOSITORY: ${{ env.GHCR_REPOSITORY }}
DATE: ${{ steps.date.outputs.date }} DATE: ${{ steps.date.outputs.date }}
run: | run: |
@ -88,10 +92,10 @@ jobs:
- -
name: Login to DockerHub name: Login to DockerHub
uses: docker/login-action@v4 uses: docker/login-action@v4
if: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }} if: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }}
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ env.DOCKERHUB_TOKEN }}
- -
name: Login to GitHub Container Registry name: Login to GitHub Container Registry
uses: docker/login-action@v4 uses: docker/login-action@v4
@ -113,15 +117,20 @@ jobs:
dockerhub-sync-readme: dockerhub-sync-readme:
needs: dockerhub-build-push needs: dockerhub-build-push
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: ${{ secrets.DOCKERHUB_USERNAME != '' && (secrets.DOCKERHUB_PASSWORD != '' || secrets.DOCKERHUB_TOKEN != '') && secrets.DOCKERHUB_REPOSITORY != '' }} env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }}
if: ${{ env.DOCKERHUB_USERNAME != '' && (env.DOCKERHUB_PASSWORD != '' || env.DOCKERHUB_TOKEN != '') && env.DOCKERHUB_REPOSITORY != '' }}
steps: steps:
- name: Sync README - name: Sync README
uses: docker://lsiodev/readme-sync:latest uses: docker://lsiodev/readme-sync:latest
env: env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_USERNAME: ${{ env.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD != '' && secrets.DOCKERHUB_PASSWORD || secrets.DOCKERHUB_TOKEN }} DOCKERHUB_PASSWORD: ${{ env.DOCKERHUB_PASSWORD != '' && env.DOCKERHUB_PASSWORD || env.DOCKERHUB_TOKEN }}
GIT_REPOSITORY: ${{ github.repository }} GIT_REPOSITORY: ${{ github.repository }}
DOCKER_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }} DOCKER_REPOSITORY: ${{ env.DOCKERHUB_REPOSITORY }}
GIT_BRANCH: master GIT_BRANCH: master
with: with:
entrypoint: node entrypoint: node