From 5206456368ea4d3defdc4b54e864eb41cbbf468f Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Thu, 2 May 2024 19:59:16 +0200 Subject: [PATCH 1/4] Run nightly build only if repository has changes --- .github/workflows/docker-nightly.yml | 50 ++++++++++++---------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/.github/workflows/docker-nightly.yml b/.github/workflows/docker-nightly.yml index d489989..3758629 100644 --- a/.github/workflows/docker-nightly.yml +++ b/.github/workflows/docker-nightly.yml @@ -8,43 +8,35 @@ on: workflow_dispatch: jobs: - check_date: - if: github.repository_owner == 'McPringle' + check: runs-on: ubuntu-latest - name: Check latest commit + name: Check latest build + outputs: - should_run: ${{ steps.should_run.outputs.should_run }} + last_build_sha: ${{ fromJson(steps.check_last_build.outputs.data).workflow_runs[0].head_sha }} + steps: - - uses: actions/checkout@v4 - - name: print latest_commit - run: echo ${{ github.sha }} - - id: should_run - continue-on-error: true - name: check latest commit is less than a day - run: | - sha=$(git rev-list --after="24 hours" ${{ github.sha }}) - if test -z $sha - then - echo "should_run=false" >> $GITHUB_OUTPUT - else - echo "should_run=true" >> $GITHUB_OUTPUT - fi + - uses: octokit/request-action@v2.x + id: check_last_build + with: + route: GET /repos/${{github.repository}}/actions/workflows/docker-nightly.yml/runs?per_page=1&status=completed + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: "echo Last daily build: ${{ fromJson(steps.check_last_build.outputs.data).workflow_runs[0].head_sha }}" + docker: - needs: check_date - if: ${{ needs.check_date.outputs.should_run != 'false' }} + if: needs.check.outputs.last_build_sha != github.sha runs-on: ubuntu-latest - name: Docker Nightly + name: Build and push Docker image + needs: check + steps: - name: Check out the repo uses: actions/checkout@v4 - - name: Check for changes - continue-on-error: true - shell: bash - run: 'test -n "$(git reflog main --since="24 hours")"' - name: Log in to Docker Hub uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} + username: ${{ github.actor }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push Docker image uses: docker/build-push-action@v5 @@ -52,10 +44,10 @@ jobs: context: . file: ./Dockerfile push: true - tags: mcpringle/apus:nightly + tags: ${{ github.actor }}/apus:nightly - name: Docker Hub Description uses: peter-evans/dockerhub-description@v4 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} + username: ${{ github.actor }} password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: mcpringle/apus + repository: ${{ github.actor }}/apus From 0713bdbb87d0523d1a72b188db9f7797fd07cb5b Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Mon, 13 May 2024 18:31:19 +0200 Subject: [PATCH 2/4] Revert to DOCKERHUB_USERNAME secret --- .github/workflows/docker-nightly.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-nightly.yml b/.github/workflows/docker-nightly.yml index 3758629..a41bc70 100644 --- a/.github/workflows/docker-nightly.yml +++ b/.github/workflows/docker-nightly.yml @@ -36,7 +36,7 @@ jobs: - name: Log in to Docker Hub uses: docker/login-action@v3 with: - username: ${{ github.actor }} + username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push Docker image uses: docker/build-push-action@v5 @@ -48,6 +48,6 @@ jobs: - name: Docker Hub Description uses: peter-evans/dockerhub-description@v4 with: - username: ${{ github.actor }} + username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} repository: ${{ github.actor }}/apus From 4a7f44d035dda65f405ef068d73f55c4649ae503 Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Mon, 13 May 2024 18:34:46 +0200 Subject: [PATCH 3/4] Simplify repository variable --- .github/workflows/docker-nightly.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-nightly.yml b/.github/workflows/docker-nightly.yml index a41bc70..dbf6970 100644 --- a/.github/workflows/docker-nightly.yml +++ b/.github/workflows/docker-nightly.yml @@ -44,10 +44,10 @@ jobs: context: . file: ./Dockerfile push: true - tags: ${{ github.actor }}/apus:nightly + tags: ${{ github.repository }}:nightly - name: Docker Hub Description uses: peter-evans/dockerhub-description@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{ github.actor }}/apus + repository: ${{ github.repository }} From 7def7b436234249a92934068b2c1e93b39f797d6 Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Mon, 13 May 2024 18:42:01 +0200 Subject: [PATCH 4/4] Extend docker build conditions --- .github/workflows/docker-nightly.yml | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-nightly.yml b/.github/workflows/docker-nightly.yml index dbf6970..079b304 100644 --- a/.github/workflows/docker-nightly.yml +++ b/.github/workflows/docker-nightly.yml @@ -8,27 +8,44 @@ on: workflow_dispatch: jobs: - check: + check-build: runs-on: ubuntu-latest name: Check latest build outputs: - last_build_sha: ${{ fromJson(steps.check_last_build.outputs.data).workflow_runs[0].head_sha }} + last-build-sha: ${{ fromJson(steps.check-last-build.outputs.data).workflow_runs[0].head_sha }} steps: - uses: octokit/request-action@v2.x - id: check_last_build + id: check-last-build with: route: GET /repos/${{github.repository}}/actions/workflows/docker-nightly.yml/runs?per_page=1&status=completed env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - run: "echo Last daily build: ${{ fromJson(steps.check_last_build.outputs.data).workflow_runs[0].head_sha }}" + - run: "echo Last daily build: ${{ fromJson(steps.check-last-build.outputs.data).workflow_runs[0].head_sha }}" + + check-secrets: + runs-on: ubuntu-latest + name: Check secrets + + outputs: + defined: ${{ steps.check-dockerhub-secrets.outputs.defined }} + + steps: + - id: check-dockerhub-secrets + shell: bash + run: | + if [[ "${{ secrets.DOCKERHUB_USERNAME }}" != '' && "${{ secrets.DOCKERHUB_TOKEN }}" ]]; then + echo "defined=true" >> $GITHUB_OUTPUT; + else + echo "defined=false" >> $GITHUB_OUTPUT; + fi docker: - if: needs.check.outputs.last_build_sha != github.sha + if: needs.check-build.outputs.last-build-sha != github.sha && needs.check-secrets.outputs.defined == 'true' runs-on: ubuntu-latest name: Build and push Docker image - needs: check + needs: [check-build, check-secrets] steps: - name: Check out the repo