Skip to content

Commit 06eb551

Browse files
committed
Fix release and add backfill-releases
1 parent 9d502a1 commit 06eb551

2 files changed

Lines changed: 162 additions & 1 deletion

File tree

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: Backfill GitHub Releases
2+
3+
on:
4+
workflow_dispatch: {}
5+
6+
permissions:
7+
id-token: write
8+
contents: write
9+
10+
jobs:
11+
backfill:
12+
name: Backfill Missing Releases
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup pnpm
21+
uses: pnpm/action-setup@v4
22+
with:
23+
version: 10.18.3
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 20
29+
cache: "pnpm"
30+
registry-url: "https://registry.npmjs.org"
31+
32+
- name: Upgrade npm for trusted publishing
33+
run: npm install -g npm@11.7.0
34+
35+
- name: Install dependencies
36+
run: pnpm install --frozen-lockfile
37+
38+
- name: Build all packages
39+
run: pnpm build
40+
41+
- name: Backfill releases and publish missing versions
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
set -euo pipefail
46+
47+
# Define publishable packages: directory => npm package name
48+
declare -A PACKAGES=(
49+
["twister"]="@plotday/twister"
50+
["tools/google-calendar"]="@plotday/tool-google-calendar"
51+
["tools/google-contacts"]="@plotday/tool-google-contacts"
52+
["tools/google-drive"]="@plotday/tool-google-drive"
53+
["tools/gmail"]="@plotday/tool-gmail"
54+
["tools/linear"]="@plotday/tool-linear"
55+
["tools/slack"]="@plotday/tool-slack"
56+
["tools/jira"]="@plotday/tool-jira"
57+
["tools/asana"]="@plotday/tool-asana"
58+
["tools/outlook-calendar"]="@plotday/tool-outlook-calendar"
59+
)
60+
61+
created=0
62+
published=0
63+
failed=0
64+
65+
for pkg_dir in "${!PACKAGES[@]}"; do
66+
npm_name="${PACKAGES[$pkg_dir]}"
67+
local_version=$(jq -r '.version' "$pkg_dir/package.json")
68+
69+
echo "=== $npm_name ($pkg_dir) ==="
70+
echo " Local version: $local_version"
71+
72+
# Get all published versions from npm
73+
npm_versions=$(npm view "$npm_name" versions --json 2>/dev/null || echo "[]")
74+
latest_npm=$(echo "$npm_versions" | jq -r 'if type == "array" then .[-1] // "none" else . end')
75+
echo " Latest npm version: $latest_npm"
76+
77+
# Check each version in CHANGELOG for missing GitHub releases
78+
changelog_file="$pkg_dir/CHANGELOG.md"
79+
if [ ! -f "$changelog_file" ]; then
80+
echo " No CHANGELOG.md found, skipping"
81+
continue
82+
fi
83+
84+
# Extract all versions from CHANGELOG
85+
changelog_versions=$(grep -oP '^## \K[0-9]+\.[0-9]+\.[0-9]+' "$changelog_file" || true)
86+
87+
for version in $changelog_versions; do
88+
# Check if this version is published on npm
89+
is_on_npm=$(echo "$npm_versions" | jq -r --arg v "$version" 'if type == "array" then (map(select(. == $v)) | length > 0) else (. == $v) end')
90+
91+
if [ "$is_on_npm" != "true" ]; then
92+
echo " v$version: not on npm, skipping GitHub release"
93+
continue
94+
fi
95+
96+
# Build tag name matching release.yml convention
97+
tag_name="${pkg_dir//\//@}@${version}"
98+
99+
# Check if GitHub release already exists
100+
if gh release view "$tag_name" &>/dev/null; then
101+
echo " v$version: GitHub release exists"
102+
continue
103+
fi
104+
105+
# Extract changelog entry for this version
106+
release_notes=$(awk "/^## ${version}/,/^## [0-9]/" "$changelog_file" | sed '1d;$d' | sed '/^$/d')
107+
if [ -z "$release_notes" ]; then
108+
release_notes="Release ${npm_name}@${version}"
109+
fi
110+
111+
echo " v$version: Creating GitHub release ($tag_name)"
112+
if gh release create "$tag_name" \
113+
--title "${npm_name}@${version}" \
114+
--notes "$release_notes" \
115+
--target main; then
116+
created=$((created + 1))
117+
else
118+
echo " v$version: Failed to create release"
119+
failed=$((failed + 1))
120+
fi
121+
done
122+
123+
# Attempt to publish if npm is behind local version
124+
if [ "$latest_npm" != "$local_version" ]; then
125+
echo " Attempting to publish $npm_name@$local_version (npm has $latest_npm)"
126+
if (cd "$pkg_dir" && npm publish --provenance --access public 2>&1); then
127+
echo " Published $npm_name@$local_version"
128+
published=$((published + 1))
129+
130+
# Create GitHub release for newly published version
131+
tag_name="${pkg_dir//\//@}@${local_version}"
132+
release_notes=$(awk "/^## ${local_version}/,/^## [0-9]/" "$changelog_file" | sed '1d;$d' | sed '/^$/d')
133+
if [ -z "$release_notes" ]; then
134+
release_notes="Release ${npm_name}@${local_version}"
135+
fi
136+
gh release create "$tag_name" \
137+
--title "${npm_name}@${local_version}" \
138+
--notes "$release_notes" \
139+
--target main || echo " Release creation failed for $tag_name"
140+
else
141+
echo " Failed to publish $npm_name@$local_version"
142+
failed=$((failed + 1))
143+
fi
144+
fi
145+
done
146+
147+
echo ""
148+
echo "=== Summary ==="
149+
echo "GitHub releases created: $created"
150+
echo "Packages published to npm: $published"
151+
echo "Failures: $failed"
152+
153+
# Write summary
154+
{
155+
echo "### Backfill Results"
156+
echo ""
157+
echo "- GitHub releases created: **$created**"
158+
echo "- Packages published to npm: **$published**"
159+
echo "- Failures: **$failed**"
160+
} >> "$GITHUB_STEP_SUMMARY"

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
workflow_dispatch: {}
78

89
concurrency: ${{ github.workflow }}-${{ github.ref }}
910

@@ -95,7 +96,7 @@ jobs:
9596
gh release create "$tag_name" \
9697
--title "${name}@${version}" \
9798
--notes "$release_notes" \
98-
--verify-tag || echo "Release creation failed for $tag_name, may already exist"
99+
--target main || echo "Release creation failed for $tag_name, may already exist"
99100
done
100101
101102
- name: Summary

0 commit comments

Comments
 (0)