refactor: move credentials checks into workflow env

This is a simpler and cleaner approach than previous implementations.

PR: #49
See: 7b71139613
See: 40f6d7bf50
This commit is contained in:
innovaker 2021-05-19 20:36:30 +01:00
parent 8e1ab724e4
commit 11a99e0826

View File

@ -4,6 +4,8 @@ env:
zephyr-version: 2.4.0 zephyr-version: 2.4.0
zephyr-sdk-version: 0.11.4 zephyr-sdk-version: 0.11.4
cache-repository-name: zmk-docker-cache cache-repository-name: zmk-docker-cache
docker-hub-credentials: ${{ secrets.DOCKER_HUB_USERNAME != null && secrets.DOCKER_HUB_TOKEN != null }}
ghcr-credentials: ${{ secrets.GHCR_USERNAME != null && secrets.GHCR_TOKEN != null }}
docker-hub-namespace: ${{ secrets.DOCKER_HUB_NAMESPACE || github.repository_owner }} docker-hub-namespace: ${{ secrets.DOCKER_HUB_NAMESPACE || github.repository_owner }}
ghcr-namespace: ${{ github.repository_owner }} ghcr-namespace: ${{ github.repository_owner }}
@ -15,20 +17,6 @@ on:
concurrency: ${{ github.workflow }} concurrency: ${{ github.workflow }}
jobs: jobs:
credentials:
runs-on: ubuntu-latest
outputs:
ghcr: ${{ steps.ghcr.outcome == 'success' }}
docker-hub: ${{ steps.docker-hub.outcome == 'success' }}
steps:
- name: Docker Hub
id: docker-hub
run: if [ ${{ secrets.DOCKER_HUB_USERNAME == null || secrets.DOCKER_HUB_TOKEN == null }} = true ]; then exit 1; fi
continue-on-error: true
- name: GitHub Container Registry
id: ghcr
run: if [ ${{ secrets.GHCR_USERNAME == null || secrets.GHCR_TOKEN == null }} = true ]; then exit 1; fi
continue-on-error: true
architectures: architectures:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
@ -75,7 +63,6 @@ jobs:
echo ::set-output name=release-trigger::${RELEASE_TRIGGER} echo ::set-output name=release-trigger::${RELEASE_TRIGGER}
candidates: candidates:
needs: needs:
- credentials
- architectures - architectures
- tags - tags
if: ${{ !startsWith(github.ref, 'refs/tags') }} if: ${{ !startsWith(github.ref, 'refs/tags') }}
@ -90,14 +77,14 @@ jobs:
steps: steps:
- name: Login to Docker Hub - name: Login to Docker Hub
id: docker-hub-login id: docker-hub-login
if: ${{ needs.credentials.outputs.docker-hub == 'true' }} if: ${{ env.docker-hub-credentials == 'true' }}
uses: docker/login-action@v1 uses: docker/login-action@v1
with: with:
username: ${{ secrets.DOCKER_HUB_USERNAME }} username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }} password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
id: ghcr-login id: ghcr-login
if: ${{ needs.credentials.outputs.ghcr == 'true' }} if: ${{ env.ghcr-credentials == 'true' }}
uses: docker/login-action@v1 uses: docker/login-action@v1
with: with:
registry: ghcr.io registry: ghcr.io
@ -129,7 +116,6 @@ jobs:
push: ${{ steps.docker-hub-login.outcome == 'success' }} push: ${{ steps.docker-hub-login.outcome == 'success' }}
releases: releases:
needs: needs:
- credentials
- architectures - architectures
- tags - tags
if: ${{ github.ref == format('refs/tags/{0}', needs.tags.outputs.release-trigger) }} if: ${{ github.ref == format('refs/tags/{0}', needs.tags.outputs.release-trigger) }}