-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (134 loc) · 5.78 KB
/
backfill-releases.yml
File metadata and controls
160 lines (134 loc) · 5.78 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
name: Backfill GitHub Releases
on:
workflow_dispatch: {}
permissions:
id-token: write
contents: write
jobs:
backfill:
name: Backfill Missing Releases
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.3
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
registry-url: "https://registry.npmjs.org"
- name: Upgrade npm for trusted publishing
run: npm install -g npm@11.7.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build all packages
run: pnpm build
- name: Backfill releases and publish missing versions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
# Define publishable packages: directory => npm package name
declare -A PACKAGES=(
["twister"]="@plotday/twister"
["tools/google-calendar"]="@plotday/tool-google-calendar"
["tools/google-contacts"]="@plotday/tool-google-contacts"
["tools/google-drive"]="@plotday/tool-google-drive"
["tools/gmail"]="@plotday/tool-gmail"
["tools/linear"]="@plotday/tool-linear"
["tools/slack"]="@plotday/tool-slack"
["tools/jira"]="@plotday/tool-jira"
["tools/asana"]="@plotday/tool-asana"
["tools/outlook-calendar"]="@plotday/tool-outlook-calendar"
)
created=0
published=0
failed=0
for pkg_dir in "${!PACKAGES[@]}"; do
npm_name="${PACKAGES[$pkg_dir]}"
local_version=$(jq -r '.version' "$pkg_dir/package.json")
echo "=== $npm_name ($pkg_dir) ==="
echo " Local version: $local_version"
# Get all published versions from npm
npm_versions=$(npm view "$npm_name" versions --json 2>/dev/null || echo "[]")
latest_npm=$(echo "$npm_versions" | jq -r 'if type == "array" then .[-1] // "none" else . end')
echo " Latest npm version: $latest_npm"
# Check each version in CHANGELOG for missing GitHub releases
changelog_file="$pkg_dir/CHANGELOG.md"
if [ ! -f "$changelog_file" ]; then
echo " No CHANGELOG.md found, skipping"
continue
fi
# Extract all versions from CHANGELOG
changelog_versions=$(grep -oP '^## \K[0-9]+\.[0-9]+\.[0-9]+' "$changelog_file" || true)
for version in $changelog_versions; do
# Check if this version is published on npm
is_on_npm=$(echo "$npm_versions" | jq -r --arg v "$version" 'if type == "array" then (map(select(. == $v)) | length > 0) else (. == $v) end')
if [ "$is_on_npm" != "true" ]; then
echo " v$version: not on npm, skipping GitHub release"
continue
fi
# Build tag name matching release.yml convention
tag_name="${pkg_dir//\//@}@${version}"
# Check if GitHub release already exists
if gh release view "$tag_name" &>/dev/null; then
echo " v$version: GitHub release exists"
continue
fi
# Extract changelog entry for this version
release_notes=$(awk "/^## ${version}/,/^## [0-9]/" "$changelog_file" | sed '1d;$d' | sed '/^$/d')
if [ -z "$release_notes" ]; then
release_notes="Release ${npm_name}@${version}"
fi
echo " v$version: Creating GitHub release ($tag_name)"
if gh release create "$tag_name" \
--title "${npm_name}@${version}" \
--notes "$release_notes" \
--target main; then
created=$((created + 1))
else
echo " v$version: Failed to create release"
failed=$((failed + 1))
fi
done
# Attempt to publish if npm is behind local version
if [ "$latest_npm" != "$local_version" ]; then
echo " Attempting to publish $npm_name@$local_version (npm has $latest_npm)"
if (cd "$pkg_dir" && npm publish --provenance --access public 2>&1); then
echo " Published $npm_name@$local_version"
published=$((published + 1))
# Create GitHub release for newly published version
tag_name="${pkg_dir//\//@}@${local_version}"
release_notes=$(awk "/^## ${local_version}/,/^## [0-9]/" "$changelog_file" | sed '1d;$d' | sed '/^$/d')
if [ -z "$release_notes" ]; then
release_notes="Release ${npm_name}@${local_version}"
fi
gh release create "$tag_name" \
--title "${npm_name}@${local_version}" \
--notes "$release_notes" \
--target main || echo " Release creation failed for $tag_name"
else
echo " Failed to publish $npm_name@$local_version"
failed=$((failed + 1))
fi
fi
done
echo ""
echo "=== Summary ==="
echo "GitHub releases created: $created"
echo "Packages published to npm: $published"
echo "Failures: $failed"
# Write summary
{
echo "### Backfill Results"
echo ""
echo "- GitHub releases created: **$created**"
echo "- Packages published to npm: **$published**"
echo "- Failures: **$failed**"
} >> "$GITHUB_STEP_SUMMARY"