From 11a99e0826c092c038a5ca49c04711a138c90480 Mon Sep 17 00:00:00 2001 From: innovaker <66737976+innovaker@users.noreply.github.com> Date: Wed, 19 May 2021 20:36:30 +0100 Subject: [PATCH] refactor: move credentials checks into workflow env This is a simpler and cleaner approach than previous implementations. PR: #49 See: 7b71139613414351ccf293331201b6d19fb93d16 See: 40f6d7bf50372132159779cc6af7e7374fd87ab7 --- .github/workflows/containers.yml | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml index d3339d1..b8ad6c0 100644 --- a/.github/workflows/containers.yml +++ b/.github/workflows/containers.yml @@ -4,6 +4,8 @@ env: zephyr-version: 2.4.0 zephyr-sdk-version: 0.11.4 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 }} ghcr-namespace: ${{ github.repository_owner }} @@ -15,20 +17,6 @@ on: concurrency: ${{ github.workflow }} 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: runs-on: ubuntu-latest outputs: @@ -75,7 +63,6 @@ jobs: echo ::set-output name=release-trigger::${RELEASE_TRIGGER} candidates: needs: - - credentials - architectures - tags if: ${{ !startsWith(github.ref, 'refs/tags') }} @@ -90,14 +77,14 @@ jobs: steps: - name: Login to Docker Hub id: docker-hub-login - if: ${{ needs.credentials.outputs.docker-hub == 'true' }} + if: ${{ env.docker-hub-credentials == 'true' }} uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Login to GitHub Container Registry id: ghcr-login - if: ${{ needs.credentials.outputs.ghcr == 'true' }} + if: ${{ env.ghcr-credentials == 'true' }} uses: docker/login-action@v1 with: registry: ghcr.io @@ -129,7 +116,6 @@ jobs: push: ${{ steps.docker-hub-login.outcome == 'success' }} releases: needs: - - credentials - architectures - tags if: ${{ github.ref == format('refs/tags/{0}', needs.tags.outputs.release-trigger) }}