-
Notifications
You must be signed in to change notification settings - Fork 2
159 lines (139 loc) · 6.2 KB
/
Copy pathsync-motoko.yml
File metadata and controls
159 lines (139 loc) · 6.2 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
name: Motoko release check
on:
schedule:
- cron: '0 8 * * 1' # Weekly on Monday
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
- name: Create GitHub App Token
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
id: app-token
with:
client-id: ${{ vars.PR_AUTOMATION_BOT_PUBLIC_CLIENT_ID }}
private-key: ${{ secrets.PR_AUTOMATION_BOT_PUBLIC_PRIVATE_KEY }}
- name: Initialize motoko submodule
run: |
git config --global url."https://github.com/".insteadOf "git@github.com:"
git submodule update --init --depth 1 .sources/motoko
- name: Get latest Motoko release tag
id: latest
run: |
RAW=$(gh release view --repo caffeinelabs/motoko --json tagName -q .tagName)
# git_tag: raw tag as it appears on the remote (no v prefix)
GIT_TAG="${RAW#v}"
# versions_tag: v-prefixed form used in VERSIONS file and PR titles
[[ "$RAW" == v* ]] && VERSIONS_TAG="$RAW" || VERSIONS_TAG="v${RAW}"
echo "git_tag=$GIT_TAG" >> $GITHUB_OUTPUT
echo "versions_tag=$VERSIONS_TAG" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Get currently pinned version
id: current
run: |
CURRENT=$(grep '^motoko ' .sources/VERSIONS | awk '{print $2}')
echo "version=$CURRENT" >> $GITHUB_OUTPUT
- name: Check if update needed
id: check
run: |
LATEST="${{ steps.latest.outputs.versions_tag }}"
CURRENT="${{ steps.current.outputs.version }}"
BRANCH="infra/bump-motoko-${LATEST}"
if [ "$LATEST" = "$CURRENT" ]; then
echo "Already at latest: $CURRENT"
echo "needed=false" >> $GITHUB_OUTPUT
elif git ls-remote --exit-code origin "refs/heads/${BRANCH}" > /dev/null 2>&1; then
echo "Branch $BRANCH already exists — PR likely open, skipping"
echo "needed=false" >> $GITHUB_OUTPUT
else
echo "New release: $LATEST (current: $CURRENT)"
echo "needed=true" >> $GITHUB_OUTPUT
fi
- name: Bump submodule to new release
if: steps.check.outputs.needed == 'true'
run: |
TAG="${{ steps.latest.outputs.git_tag }}"
# Fetch the specific tag shallowly; fall back to fetching all tags if that fails
if ! git -C .sources/motoko fetch --depth 1 origin "refs/tags/${TAG}:refs/tags/${TAG}"; then
git -C .sources/motoko fetch --unshallow --tags origin
fi
git -C .sources/motoko checkout "tags/${TAG}"
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
if: steps.check.outputs.needed == 'true'
with:
node-version: 22
cache: npm
- name: Install dependencies
if: steps.check.outputs.needed == 'true'
run: npm ci
- name: Initialize examples submodule (required for build)
if: steps.check.outputs.needed == 'true'
run: git submodule update --init --depth 1 .sources/examples
- name: Run Motoko sync
if: steps.check.outputs.needed == 'true'
run: npm run sync:motoko
- name: Build check
if: steps.check.outputs.needed == 'true'
run: npm run build
- name: Update VERSIONS file
if: steps.check.outputs.needed == 'true'
run: |
NEW_TAG="${{ steps.latest.outputs.versions_tag }}"
NEW_HASH=$(git -C .sources/motoko rev-parse --short HEAD)
sed -i "s|^motoko .*|motoko ${NEW_TAG} ${NEW_HASH}|" .sources/VERSIONS
- name: Read sync warnings
if: steps.check.outputs.needed == 'true'
id: warnings
run: |
if [ -f /tmp/sync-motoko-warnings.txt ]; then
WARNINGS=$(cat /tmp/sync-motoko-warnings.txt)
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$WARNINGS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "body=" >> $GITHUB_OUTPUT
fi
- name: Create PR
if: steps.check.outputs.needed == 'true'
run: |
git config user.name "pr-automation-bot-public[bot]"
git config user.email "pr-automation-bot-public[bot]@users.noreply.github.com"
BRANCH="infra/bump-motoko-${{ steps.latest.outputs.versions_tag }}"
git checkout -b "$BRANCH"
git add .sources/motoko .sources/VERSIONS docs/languages/motoko/
git commit -m "chore: bump Motoko to ${{ steps.latest.outputs.versions_tag }}"
git push -u origin "$BRANCH"
WARNINGS="${{ steps.warnings.outputs.body }}"
{
echo "## Summary"
echo ""
echo "Automated bump of \`.sources/motoko\` from \`${{ steps.current.outputs.version }}\` to \`${{ steps.latest.outputs.versions_tag }}\`."
echo ""
echo "- Ran \`npm run sync:motoko\` — synced docs from the new release"
echo "- Build passed ✓"
echo ""
if [ -n "$WARNINGS" ]; then
echo "## ⚠️ Warnings — manual review required"
echo ""
echo "$WARNINGS"
echo ""
fi
echo "## Checklist"
echo ""
echo "- [ ] Review synced content for breaking changes"
echo "- [ ] Check [release notes](https://github.com/caffeinelabs/motoko/releases/tag/${{ steps.latest.outputs.git_tag }}) for API or syntax changes that affect hand-written docs"
echo "- [ ] Verify any new sections or renamed files are handled correctly"
echo ""
echo "## Sync recommendation"
echo ""
echo "\`sync from caffeinelabs/motoko doc/md\`"
} > /tmp/pr-body.md
gh pr create \
--title "chore: bump Motoko to ${{ steps.latest.outputs.versions_tag }}" \
--body-file /tmp/pr-body.md
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}