-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
174 lines (154 loc) · 6.39 KB
/
action.yml
File metadata and controls
174 lines (154 loc) · 6.39 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: 'Sync TASKS.md to GitHub Project'
description: 'One-way sync from TASKS.md to a GitHub Projects v2 board'
inputs:
tasks-file:
description: 'Path to the TASKS.md file'
required: false
default: 'TASKS.md'
org:
description: 'GitHub organization login'
required: true
project-number:
description: 'GitHub Project board number'
required: true
repo-label:
description: 'Label to scope archive detection to this repos items'
required: false
default: ''
github-token:
description: 'GitHub token with project scope'
required: true
dry-run:
description: 'If true, only log what would change'
required: false
default: 'false'
writeback:
description: 'If true, write board item IDs back into TASKS.md after sync'
required: false
default: 'true'
writeback-pr:
description: 'If true, open a PR for writeback changes instead of pushing directly (for repos with branch protection on main)'
required: false
default: 'false'
repo:
description: 'Target repository for creating real Issues instead of DraftIssues (format: owner/name)'
required: false
default: ''
outputs:
created:
description: 'Number of board items created'
value: ${{ steps.sync.outputs.created }}
updated:
description: 'Number of board items updated'
value: ${{ steps.sync.outputs.updated }}
archived:
description: 'Number of board items archived'
value: ${{ steps.sync.outputs.archived }}
unchanged:
description: 'Number of unchanged board items'
value: ${{ steps.sync.outputs.unchanged }}
runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Install tasksmd-sync
shell: bash
run: pip install "${{ github.action_path }}"
- name: Run sync
id: sync
shell: bash
env:
TASKSMD_GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
ARGS="${{ inputs.tasks-file }}"
ARGS="$ARGS --org ${{ inputs.org }}"
ARGS="$ARGS --project-number ${{ inputs.project-number }}"
ARGS="$ARGS --output-json /tmp/tasksmd-sync-result.json"
ARGS="$ARGS --verbose"
if [ -n "${{ inputs.repo-label }}" ]; then
ARGS="$ARGS --repo-label '${{ inputs.repo-label }}'"
fi
if [ -n "${{ inputs.repo }}" ]; then
ARGS="$ARGS --repo '${{ inputs.repo }}'"
fi
if [ "${{ inputs.dry-run }}" = "true" ]; then
ARGS="$ARGS --dry-run"
fi
if [ "${{ inputs.writeback }}" = "true" ]; then
ARGS="$ARGS --writeback"
fi
eval tasksmd-sync $ARGS
# Parse results for outputs
if [ -f /tmp/tasksmd-sync-result.json ]; then
echo "created=$(python3 -c "import json; print(json.load(open('/tmp/tasksmd-sync-result.json'))['created'])")" >> "$GITHUB_OUTPUT"
echo "updated=$(python3 -c "import json; print(json.load(open('/tmp/tasksmd-sync-result.json'))['updated'])")" >> "$GITHUB_OUTPUT"
echo "archived=$(python3 -c "import json; print(json.load(open('/tmp/tasksmd-sync-result.json'))['archived'])")" >> "$GITHUB_OUTPUT"
echo "unchanged=$(python3 -c "import json; print(json.load(open('/tmp/tasksmd-sync-result.json'))['unchanged'])")" >> "$GITHUB_OUTPUT"
fi
- name: Commit writeback changes
if: inputs.writeback == 'true' && inputs.dry-run != 'true'
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
if git diff --quiet "${{ inputs.tasks-file }}"; then
echo "No writeback changes to commit"
exit 0
fi
git config user.name "tasksmd-sync[bot]"
git config user.email "tasksmd-sync[bot]@users.noreply.github.com"
git remote set-url origin "https://x-access-token:${{ inputs.github-token }}@github.com/${{ github.repository }}.git"
if [ "${{ inputs.writeback-pr }}" = "true" ]; then
BRANCH="chore/tasksmd-sync-writeback"
BASE="${{ github.ref_name }}"
git checkout -b "$BRANCH"
git add "${{ inputs.tasks-file }}"
git commit -m "chore: write back board item IDs to ${{ inputs.tasks-file }}"
git push origin "$BRANCH" --force
EXISTING=$(gh pr list --head "$BRANCH" --base "$BASE" --json number -q '.[0].number' 2>/dev/null || true)
if [ -z "$EXISTING" ]; then
gh pr create \
--head "$BRANCH" \
--base "$BASE" \
--title "chore: write back board item IDs to ${{ inputs.tasks-file }}" \
--body "Automated writeback of project board item IDs by tasksmd-sync. Merge this to keep TASKS.md in sync with the project board."
else
echo "PR #$EXISTING already exists for $BRANCH; updated with force push."
fi
else
git add "${{ inputs.tasks-file }}"
git commit -m "chore: write back board item IDs to ${{ inputs.tasks-file }}"
git push
fi
- name: Comment on PR (dry-run)
if: github.event_name == 'pull_request' && inputs.dry-run == 'true'
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
if [ ! -f /tmp/tasksmd-sync-result.json ]; then
exit 0
fi
# Only comment when the tasks file was changed in this PR
if ! gh pr diff "${{ github.event.pull_request.number }}" --name-only \
| grep -qxF "${{ inputs.tasks-file }}"; then
echo "Tasks file not changed in this PR; skipping comment."
exit 0
fi
CREATED=$(python3 -c "import json; print(json.load(open('/tmp/tasksmd-sync-result.json'))['created'])")
UPDATED=$(python3 -c "import json; print(json.load(open('/tmp/tasksmd-sync-result.json'))['updated'])")
ARCHIVED=$(python3 -c "import json; print(json.load(open('/tmp/tasksmd-sync-result.json'))['archived'])")
UNCHANGED=$(python3 -c "import json; print(json.load(open('/tmp/tasksmd-sync-result.json'))['unchanged'])")
BODY="## TASKS.md Sync Preview (dry run)
| Action | Count |
|--------|-------|
| Create | $CREATED |
| Update | $UPDATED |
| Archive | $ARCHIVED |
| Unchanged | $UNCHANGED |
> This is a preview. Changes will be applied when merged to main."
gh pr comment "${{ github.event.pull_request.number }}" \
--body "$BODY" --edit-last --create-if-none