ci: Change to login and push only when push is needed #101
Workflow file for this run
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 | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- "*" | |
pull_request: | |
concurrency: | |
group: ${{ github.head_ref || github.sha }}-${{ github.workflow }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
name: ${{ matrix.id }} | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
id: | |
- "alpine" | |
- "debian" | |
steps: | |
- name: Parse ID | |
run: | | |
set -x | |
distribution=${{ matrix.id }} | |
case "${{ github.ref }}" in | |
refs/tags/*) | |
version=$(echo "${{ github.ref }}" | sed -e "s,^refs/tags/,,g") | |
;; | |
*) | |
version=latest | |
;; | |
esac | |
tags="groonga/groonga:${version}-${{ matrix.id }}" | |
if [ ${{ matrix.id }} = "debian" -a "${version}" = "latest" ]; then | |
tags="${tags},groonga/groonga:latest" | |
fi | |
need_push="no" | |
if [ "${GITHUB_EVENT_NAME}" = "push" ]; then | |
need_push="yes" | |
fi | |
echo "DISTRIBUTION=${distribution}" >> ${GITHUB_ENV} | |
echo "CONTEXT=./${distribution}" >> ${GITHUB_ENV} | |
echo "TAGS=${tags}" >> ${GITHUB_ENV} | |
echo "NEED_PUSH=${need_push}" >> ${GITHUB_ENV} | |
- uses: actions/checkout@v4 | |
- uses: docker/login-action@v3 | |
if: env.NEED_PUSH == 'yes' | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- uses: docker/setup-buildx-action@v3 | |
id: buildx | |
- uses: docker/build-push-action@v6 | |
id: docker_build | |
with: | |
# cache-from: type=gha | |
# cache-to: type=gha,mode=max | |
context: ${{ env.CONTEXT }} | |
push: ${{ env.NEED_PUSH == 'yes' }} | |
tags: ${{ env.TAGS }} | |
- name: Image info | |
run: | | |
echo "ref: ${{ github.ref }}" | |
echo "tags: ${{ env.TAGS }}" | |
echo "digest: ${{ steps.docker_build.outputs.digest }}" |