-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (63 loc) · 2.45 KB
/
sync-versions.yml
File metadata and controls
72 lines (63 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Sync Task Version
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
jobs:
check-latest:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get latest Task release
id: latest
run: |
LATEST=$(curl -s https://api.github.com/repos/go-task/task/releases/latest | jq -r '.tag_name')
echo "version=${LATEST}" >> $GITHUB_OUTPUT
echo "Latest Task version: ${LATEST}"
- name: Check version cache
id: cache
run: |
if [ -f .task-version ]; then
CACHED_VERSION=$(cat .task-version)
echo "cached_version=${CACHED_VERSION}" >> $GITHUB_OUTPUT
echo "Cached Task version: ${CACHED_VERSION}"
else
echo "cached_version=" >> $GITHUB_OUTPUT
echo "No cached version found"
fi
- name: Update version cache and trigger build
if: steps.cache.outputs.cached_version != steps.latest.outputs.version
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
fs.writeFileSync('.task-version', '${{ steps.latest.outputs.version }}');
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'build-and-push.yml',
ref: 'main',
inputs: {
task_version: '${{ steps.latest.outputs.version }}'
}
});
console.log('Version changed - build triggered');
- name: Commit cache update if version changed
if: steps.cache.outputs.cached_version != steps.latest.outputs.version
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
try {
execSync('git config --global user.email "github-actions[bot]@users.noreply.github.com"');
execSync('git config --global user.name "github-actions[bot]"');
execSync('git add .task-version');
execSync('git commit -m "chore: update cached Task version to ${{ steps.latest.outputs.version }}"');
execSync('git push');
} catch (error) {
console.log('No changes to commit or push failed:', error.message);
}