Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run nightly build only if repository has changes #112

Merged
merged 7 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions .github/workflows/docker-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,48 @@ on:
workflow_dispatch:

jobs:
check_date:
if: github.repository_owner == 'McPringle'
check-build:
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
- uses: octokit/[email protected]
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 }}"

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: |
sha=$(git rev-list --after="24 hours" ${{ github.sha }})
if test -z $sha
then
echo "should_run=false" >> $GITHUB_OUTPUT
if [[ "${{ secrets.DOCKERHUB_USERNAME }}" != '' && "${{ secrets.DOCKERHUB_TOKEN }}" ]]; then
echo "defined=true" >> $GITHUB_OUTPUT;
else
echo "should_run=true" >> $GITHUB_OUTPUT
echo "defined=false" >> $GITHUB_OUTPUT;
fi

docker:
needs: check_date
if: ${{ needs.check_date.outputs.should_run != 'false' }}
if: needs.check-build.outputs.last-build-sha != github.sha && needs.check-secrets.outputs.defined == 'true'
runs-on: ubuntu-latest
name: Docker Nightly
name: Build and push Docker image
needs: [check-build, check-secrets]

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:
Expand All @@ -52,10 +61,10 @@ jobs:
context: .
file: ./Dockerfile
push: true
tags: mcpringle/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: mcpringle/apus
repository: ${{ github.repository }}