|
| 1 | +name: Discourse Branch Update Check |
| 2 | + |
| 3 | +on: |
| 4 | + #schedule: |
| 5 | + # Runs once a week |
| 6 | + #- cron: '34 6 * * 5' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-updates: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + include: |
| 15 | + - branch: latest |
| 16 | + workflow: latest.yml |
| 17 | + - branch: esr |
| 18 | + workflow: esr.yml |
| 19 | + steps: |
| 20 | + - id: retrieve-lastrev |
| 21 | + env: |
| 22 | + branch: ${{ matrix.branch }} |
| 23 | + run: | |
| 24 | + git clone --bare --filter=blob:none --depth=1 --single-branch --branch=${branch} https://github.com/discourse/discourse disc |
| 25 | + git -C disc rev-parse @ > last-revision |
| 26 | + cp last-revision current-revision |
| 27 | + - id: cache |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: last-revision |
| 31 | + key: uscheck-${{ matrix.branch }}-${{ hashFiles('last-revision') }} |
| 32 | + restore-keys: | |
| 33 | + uscheck-${{ matrix.branch }}- |
| 34 | + - id: trigger-wf |
| 35 | + env: |
| 36 | + branch: ${{ matrix.branch }} |
| 37 | + workflow: ${{ matrix.workflow }} |
| 38 | + cache_hit: ${{ steps.cache.outputs.cache-hit }} |
| 39 | + GH_TOKEN: ${{ github.token }} |
| 40 | + run: | |
| 41 | + NEW_REV=$(cat current-revision) |
| 42 | + # cache_hit is empty on initial; false when an older cache was restored |
| 43 | + [ -n "${cache_hit}" ] && OLD_REV=$(cat last-revision || true) |
| 44 | + ls -l current-revision last-revision |
| 45 | + echo "NEW_REV=$NEW_REV" |
| 46 | + echo "OLD_REV=$OLD_REV" |
| 47 | + echo "cache_hit=$cache_hit" |
| 48 | + if [ "$NEW_REV" != "$OLD_REV" ]; then |
| 49 | + echo "Changes detected" |
| 50 | + echo "🆕 Discourse branch ${branch} revision changed" >> $GITHUB_STEP_SUMMARY |
| 51 | + echo >> $GITHUB_STEP_SUMMARY |
| 52 | + echo "Latest commit: https://github.com/discourse/discourse/commit/${NEW_REV}" >> $GITHUB_STEP_SUMMARY |
| 53 | + echo >> $GITHUB_STEP_SUMMARY |
| 54 | + if [ -n "${cache_hit}" ]; then |
| 55 | + echo "Changes: https://github.com/discourse/discourse/compare/${OLD_REV}...${NEW_REV}" >> $GITHUB_STEP_SUMMARY |
| 56 | + echo >> $GITHUB_STEP_SUMMARY |
| 57 | + fi |
| 58 | + echo "Triggering workflow: ${workflow}" >> $GITHUB_STEP_SUMMARY |
| 59 | + |
| 60 | + echo "$NEW_REV" > last-revision |
| 61 | + gh api \ |
| 62 | + --method POST \ |
| 63 | + -H "Accept: application/vnd.github+json" \ |
| 64 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 65 | + /repos/${GITHUB_REPOSITORY}/actions/workflows/${workflow}/dispatches \ |
| 66 | + -f "ref=${GITHUB_REF_NAME}" |
| 67 | + else |
| 68 | + echo "🆗 No changes in Discourse branch: ${branch}" >> $GITHUB_STEP_SUMMARY |
| 69 | + fi |
0 commit comments