diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b110706a..026dde1c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,14 +4,16 @@ on: create: tags: - '^\d{4}\.\d{2}\.\d{2}-\d+$' - #schedule: - # - cron: '0 0 * * 1' # @TODO would probably be better to have a separate workflow for automatic updates when possible workflow_dispatch: env: - REF_CORE: development-v6 # commit hash or tag - REF_WEB: development-v6 # commit hash or tag - REF_FTL: development-v6 # commit hash or tag + CORE_HASH: development-v6 + WEB_HASH: development-v6 + FTL_HASH: development-v6 + CORE_BRANCH: development-v6 + WEB_BRANCH: development-v6 + FTL_BRANCH: development-v6 +# @TODO when v6 is released *_HASH should be set commit hashes and *_BRANCH to release branches jobs: set-version: @@ -44,7 +46,7 @@ jobs: uses: actions/checkout@v4 with: repository: pi-hole/pi-hole - ref: ${{ env.REF_CORE }} + ref: ${{ startsWith(github.ref, 'refs/tags/') && env.CORE_HASH || env.CORE_BRANCH }} path: ./stage - name: Cache result @@ -89,7 +91,7 @@ jobs: uses: actions/checkout@v4 with: repository: pi-hole/web - ref: ${{ env.REF_WEB }} + ref: ${{ startsWith(github.ref, 'refs/tags/') && env.WEB_HASH || env.WEB_BRANCH }} path: ./stage - name: Cache result @@ -165,7 +167,7 @@ jobs: uses: actions/checkout@v4 with: repository: pi-hole/FTL - ref: ${{ env.REF_FTL }} + ref: ${{ startsWith(github.ref, 'refs/tags/') && env.FTL_HASH || env.FTL_BRANCH }} path: ./stage - name: Cache result @@ -390,8 +392,6 @@ jobs: if: ${{ startsWith(github.ref, 'refs/tags/') }} with: files: ./artifacts/*/*.ipk - draft: true - # @TODO Draft probably not needed anymore after v6 releases - name: Collect new packages run: | diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 00000000..db4f1a81 --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,138 @@ +name: Auto Update + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + +env: + CORE_BRANCH: development-v6 + WEB_BRANCH: development-v6 + FTL_BRANCH: development-v6 +# @TODO when v6 is released these should be set to release branches + +jobs: + check: + concurrency: check + runs-on: ubuntu-latest + continue-on-error: true + + outputs: + CORE_HASH: ${{ steps.new-hashes.outputs.CORE_HASH }} + WEB_HASH: ${{ steps.new-hashes.outputs.WEB_HASH }} + FTL_HASH: ${{ steps.new-hashes.outputs.FTL_HASH }} + STATUS: ${{ steps.status.outputs.RESULT }} + + steps: + - name: Checkout own repository + uses: actions/checkout@v4 + + - name: Checkout pi-hole/pi-hole repository + uses: actions/checkout@v4 + with: + repository: pi-hole/pi-hole + ref: ${{ env.CORE_BRANCH }} + path: ./dev/core + + - name: Checkout pi-hole/web repository + uses: actions/checkout@v4 + with: + repository: pi-hole/web + ref: ${{ env.WEB_BRANCH }} + path: ./dev/web + + - name: Checkout pi-hole/FTL repository + uses: actions/checkout@v4 + with: + repository: pi-hole/FTL + ref: ${{ env.FTL_BRANCH }} + path: ./dev/FTL + + - name: Set old hashes + id: old-hashes + run: | + echo "CORE_HASH=$(sed -n "s/^ CORE_HASH: \([[:alnum:]]*\).*$/\1/p" ./.github/workflows/build.yml)" >> $GITHUB_OUTPUT + echo "WEB_HASH=$(sed -n "s/^ WEB_HASH: \([[:alnum:]]*\).*$/\1/p" ./.github/workflows/build.yml)" >> $GITHUB_OUTPUT + echo "FTL_HASH=$(sed -n "s/^ FTL_HASH: \([[:alnum:]]*\).*$/\1/p" ./.github/workflows/build.yml)" >> $GITHUB_OUTPUT + + - name: Set new hashes + id: new-hashes + run: | + echo "CORE_HASH=$(git -C "./dev/core" rev-parse HEAD)" >> $GITHUB_OUTPUT + echo "WEB_HASH=$(git -C "./dev/web" rev-parse HEAD)" >> $GITHUB_OUTPUT + echo "FTL_HASH=$(git -C "./dev/FTL" rev-parse HEAD)" >> $GITHUB_OUTPUT + + - name: Old hashes are not empty + if: ${{ steps.old-hashes.outputs.CORE_HASH == '' || steps.old-hashes.outputs.WEB_HASH == '' || steps.old-hashes.outputs.FTL_HASH == '' }} + run: exit 1 + + - name: At least one hash is different + if: ${{ steps.old-hashes.outputs.CORE_HASH == steps.new-hashes.outputs.CORE_HASH && steps.old-hashes.outputs.WEB_HASH == steps.new-hashes.outputs.WEB_HASH && steps.old-hashes.outputs.FTL_HASH == steps.new-hashes.outputs.FTL_HASH}} + run: exit 1 + + - name: Apply patches (core) + id: patch-core + uses: ./.github/actions/patch + with: + patches_prefix: core + git_path: ./dev/core + + - name: Apply patches (web) + id: patch-web + uses: ./.github/actions/patch + with: + patches_prefix: web + git_path: ./dev/web + + - name: Apply patches (FTL) + id: patch-FTL + uses: ./.github/actions/patch + with: + patches_prefix: FTL + git_path: ./dev/FTL + + - name: Set status + id: status + run: echo "RESULT=true" >> $GITHUB_OUTPUT + + update: + concurrency: update + needs: [check] + if: ${{ needs.check.outputs.STATUS == 'true' }} + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout own repository + uses: actions/checkout@v4 + + - name: Replace refs in build workflow + run: | + sed 's/ CORE_HASH:.*$/ CORE_HASH: ${{ needs.check.outputs.CORE_HASH }}/' -i ./.github/workflows/build.yml + sed 's/ WEB_HASH:.*$/ WEB_HASH: ${{ needs.check.outputs.WEB_HASH }}/' -i ./.github/workflows/build.yml + sed 's/ FTL_HASH:.*$/ FTL_HASH: ${{ needs.check.outputs.FTL_HASH }}/' -i ./.github/workflows/build.yml + + - name: Is repository modified? + id: modified + run: | + echo "RESULT=$([ "git diff" != "" ] && echo yes || echo no)" >> $GITHUB_OUTPUT + + - name: Create tag + if: ${{ steps.modified.outputs.RESULT == 'yes' }} + id: tag + run: echo "RESULT=$(bash ./scripts/tag.sh)" >> $GITHUB_OUTPUT + + - name: Print tag and changes + run: | + echo "New tag: ${{ steps.tag.outputs.RESULT }}" + git diff + + - name: Commit and Push changes + if: ${{ steps.tag.outputs.RESULT != '' && github.event_name == 'schedule' }} + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'Automatic update to ${{ steps.tag.outputs.RESULT }}' + file_pattern: ./.github/workflow/build.yml + tagging_message: ${{ steps.tag.outputs.RESULT }} diff --git a/scripts/tag.sh b/scripts/tag.sh new file mode 100644 index 00000000..6827dd0a --- /dev/null +++ b/scripts/tag.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Made by Jack'lul + +REVISION=0 +TAG="" +LIMIT=100 + +while [ "$TAG" = "" ] || git tag | grep -q "$TAG"; do + REVISION=$((REVISION+1)) + TAG=$(date +%Y.%m.%d)-$REVISION + + LIMIT=$((LIMIT-1)) + if [ $LIMIT -le 0 ]; then + exit 1 + fi +done + +echo "$TAG"