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.
This commit is contained in:
parent
6c8efe2a50
commit
7fa4d6a3d1
1 changed files with 32 additions and 11 deletions
43
.github/workflows/main.yml
vendored
43
.github/workflows/main.yml
vendored
|
|
@ -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<<EOF'
|
||||
if [ -n "$DOCKERHUB_REPOSITORY" ]; then
|
||||
echo "${DOCKERHUB_REPOSITORY}:latest"
|
||||
echo "${DOCKERHUB_REPOSITORY}:${DATE}"
|
||||
fi
|
||||
echo "${GHCR_REPOSITORY}:latest"
|
||||
echo "${GHCR_REPOSITORY}:${DATE}"
|
||||
echo EOF
|
||||
} >> "$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}\`"
|
||||
|
|
|
|||
Loading…
Reference in a new issue