|
| 1 | +on: |
| 2 | + schedule: |
| 3 | + - cron: "7,37 * * * *" # every 30 min at :07 and :37 |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +concurrency: |
| 7 | + group: opencode-release-watch |
| 8 | + cancel-in-progress: false |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-release: |
| 15 | + if: vars.OPENCODE_WATCH_ENABLED != 'false' |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 5 |
| 18 | + steps: |
| 19 | + - id: fetch |
| 20 | + env: |
| 21 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + run: | |
| 23 | + data=$(gh release view --repo anomalyco/opencode --json tagName,name,url 2>/dev/null || echo '{}') |
| 24 | + tag=$(echo "$data" | jq -r '.tagName // empty') |
| 25 | + [ -z "$tag" ] && { echo "tag=" >> "$GITHUB_OUTPUT"; exit 0; } |
| 26 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 27 | + echo "name=$(echo "$data" | jq -r '.name // .tagName')" >> "$GITHUB_OUTPUT" |
| 28 | + echo "url=$(echo "$data" | jq -r '.url')" >> "$GITHUB_OUTPUT" |
| 29 | +
|
| 30 | + - if: steps.fetch.outputs.tag != '' |
| 31 | + id: cache |
| 32 | + uses: actions/cache/restore@v4 |
| 33 | + with: |
| 34 | + path: .cache/last-seen |
| 35 | + key: last-seen-${{ steps.fetch.outputs.tag }} |
| 36 | + restore-keys: last-seen- |
| 37 | + |
| 38 | + - if: steps.fetch.outputs.tag != '' && steps.cache.outputs.cache-hit != 'true' |
| 39 | + name: Trigger opencode sync |
| 40 | + env: |
| 41 | + URL: ${{ secrets.OPENCODE_WATCH_SYNC_URL }} |
| 42 | + SECRET: ${{ secrets.OPENCODE_WATCH_SYNC_SECRET }} |
| 43 | + run: | |
| 44 | + if [ -n "$URL" ] && [ -n "$SECRET" ]; then |
| 45 | + curl -sf -X POST "$URL" -H "x-sync-secret: $SECRET" -H "Content-Type: application/json" -d '{}' || true |
| 46 | + fi |
| 47 | +
|
| 48 | + - if: steps.fetch.outputs.tag != '' && steps.cache.outputs.cache-hit != 'true' |
| 49 | + name: Notify Slack |
| 50 | + uses: slackapi/slack-github-action@v2.0.0 |
| 51 | + with: |
| 52 | + webhook: ${{ secrets.OPENCODE_WATCH_SLACK_WEBHOOK }} |
| 53 | + webhook-type: incoming-webhook |
| 54 | + payload: | |
| 55 | + name: "${{ steps.fetch.outputs.name }}" |
| 56 | + tag: "${{ steps.fetch.outputs.tag }}" |
| 57 | + url: "${{ steps.fetch.outputs.url }}" |
| 58 | +
|
| 59 | + - if: steps.fetch.outputs.tag != '' && steps.cache.outputs.cache-hit != 'true' |
| 60 | + name: Mark tag as seen |
| 61 | + run: mkdir -p .cache/last-seen && echo "${{ steps.fetch.outputs.tag }}" > .cache/last-seen/tag.txt |
| 62 | + |
| 63 | + - if: success() && steps.fetch.outputs.tag != '' && steps.cache.outputs.cache-hit != 'true' |
| 64 | + name: Save seen-tag cache |
| 65 | + uses: actions/cache/save@v4 |
| 66 | + with: |
| 67 | + path: .cache/last-seen |
| 68 | + key: last-seen-${{ steps.fetch.outputs.tag }} |
| 69 | + |
0 commit comments