Skip to content

Commit a2d34cc

Browse files
rcosta358codex
andauthored
Require passing checks before publishing (#139)
Part of #126. Depends on #138. Publish the exact VSIX produced by the reusable checks workflow. Prepare releases through a version-bump PR, then tag the merged main commit with `./release.sh --tag VERSION`. Retain checked artifacts for one day. A repository administrator still needs to require Checks on main. Validated shell/workflow syntax, extension installation, and a disposable repository simulation of the release PR and post-merge tag flow. 🤖 Generated with [Codex](https://openai.com/codex/) --------- Co-authored-by: Codex <noreply@openai.com>
1 parent f0946db commit a2d34cc

4 files changed

Lines changed: 119 additions & 52 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,29 @@ on:
66
- 'v*'
77

88
jobs:
9+
checks:
10+
uses: ./.github/workflows/test.yml
11+
912
publish:
13+
needs: checks
1014
runs-on: ubuntu-latest
1115

1216
steps:
13-
- name: Checkout
14-
uses: actions/checkout@v4
15-
16-
- name: Setup Java
17-
uses: actions/setup-java@v4
17+
- name: Download checked extension
18+
uses: actions/download-artifact@v4
1819
with:
19-
java-version: 21
20-
distribution: temurin
20+
name: liquid-java-vsix
2121

2222
- name: Setup Node.js
2323
uses: actions/setup-node@v4
2424
with:
2525
node-version: 22
2626

27-
- name: Build Server JAR
28-
working-directory: ./server
29-
run: |
30-
mvn -B -ntp clean package -DskipTests
31-
mkdir -p ../client/server
32-
cp target/language-server-liquidjava.jar ../client/server/
33-
34-
- name: Install dependencies and build
35-
working-directory: ./client
36-
run: |
37-
npm install
38-
npm run package
39-
4027
- name: Install vsce
4128
run: npm install -g @vscode/vsce
4229

43-
- name: Package extension
44-
working-directory: ./client
45-
run: vsce package --no-dependencies --out liquid-java.vsix
46-
4730
- name: Publish to VS Code Marketplace
48-
working-directory: ./client
4931
run: vsce publish --packagePath liquid-java.vsix -p ${{ secrets.VSCE_TOKEN }}
5032

5133
- name: Publish to Open VSX Marketplace
52-
working-directory: ./client
5334
run: npx ovsx publish liquid-java.vsix --pat ${{ secrets.OVSX_TOKEN }}

‎.github/workflows/test.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ jobs:
6363
unzip -Z1 liquid-java.vsix > /tmp/liquid-java-vsix-files.txt
6464
grep -Fx 'extension/dist/server/language-server-liquidjava.jar' /tmp/liquid-java-vsix-files.txt
6565
grep -Fx 'extension/media/webview.js' /tmp/liquid-java-vsix-files.txt
66+
67+
- name: Upload checked extension
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: liquid-java-vsix
71+
path: client/liquid-java.vsix
72+
if-no-files-found: error
73+
retention-days: 1

‎CONTRIBUTING.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,26 @@ Use `./install.sh --skip-server` to package and install the extension without re
3232

3333
### Releasing
3434

35-
To create and push a git tag that will trigger the GitHub Actions workflow that automatically publishes the extension in both the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=AlcidesFonseca.liquid-java) and the [Open VSX Registry](https://open-vsx.org/extension/AlcidesFonseca/liquid-java), run the release script from the repository root:
35+
Create a version bump pull request from `main` with the release script:
3636

3737
```bash
3838
./release.sh
3939
```
4040

41-
By default, the script bumps the patch version in [client/package.json](./client/package.json).
42-
To release a manually bumped version instead, pass the version explicitly; it must match the version in [client/package.json](./client/package.json):
41+
By default, this bumps the patch version in [client/package.json](./client/package.json). Pass a version to set it explicitly:
4342

4443
```bash
4544
./release.sh <new-version>
4645
```
4746

47+
After the pull request passes Checks and is merged, create and push its release tag from `main`:
48+
49+
```bash
50+
./release.sh --tag <new-version>
51+
```
52+
53+
The tag runs Checks again and publishes the verified extension artifact to the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=AlcidesFonseca.liquid-java) and the [Open VSX Registry](https://open-vsx.org/extension/AlcidesFonseca/liquid-java).
54+
4855
### Development Mode
4956

5057
To run the extension in development mode, follow these steps:

‎release.sh‎

Lines changed: 94 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,113 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
VERSION=$1
3+
set -euo pipefail
44

5-
# check valid version format
6-
if [ -n "$VERSION" ] && [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
7-
echo "Version must be in format 1.2.3"
5+
usage() {
6+
echo "Usage: ./release.sh [VERSION] | ./release.sh --tag VERSION" >&2
7+
}
8+
9+
MODE="pr"
10+
if [[ "${1:-}" == "--tag" ]]; then
11+
MODE="tag"
12+
shift
13+
fi
14+
15+
if [[ $# -gt 1 ]] || [[ "$MODE" == "tag" && $# -ne 1 ]]; then
16+
usage
17+
exit 1
18+
fi
19+
20+
VERSION="${1:-}"
21+
if [[ -n "$VERSION" && ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
22+
echo "Version must be in format 1.2.3" >&2
823
exit 1
924
fi
1025

11-
# check current branch
1226
CURRENT_BRANCH=$(git branch --show-current)
13-
if [ "$CURRENT_BRANCH" != "main" ]; then
14-
echo "Releases can only be created from the main branch (current: $CURRENT_BRANCH)"
27+
if [[ "$CURRENT_BRANCH" != "main" ]]; then
28+
echo "Releases must start from main (current: $CURRENT_BRANCH)" >&2
1529
exit 1
1630
fi
1731

18-
# bump patch version if no version provided
19-
if [ -z "$VERSION" ]; then
20-
(cd client && npm version patch --no-git-tag-version)
21-
VERSION=$(node -p "require('./client/package.json').version")
32+
if [[ -n "$(git status --porcelain)" ]]; then
33+
echo "Releases require a clean working tree" >&2
34+
exit 1
2235
fi
2336

24-
# check if version present in package.json
25-
if ! grep -q "\"version\": \"$VERSION\"" ./client/package.json; then
26-
echo "Version $VERSION not found in package.json"
37+
git pull --ff-only origin main
38+
if [[ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]]; then
39+
echo "Local main must match origin/main before releasing" >&2
2740
exit 1
2841
fi
2942

30-
# check if version tag already exists
31-
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
32-
echo "Release $VERSION already exists"
43+
if [[ "$MODE" == "tag" ]]; then
44+
CURRENT_VERSION=$(node -p "require('./client/package.json').version")
45+
if [[ "$CURRENT_VERSION" != "$VERSION" ]]; then
46+
echo "Version $VERSION is not the version on main ($CURRENT_VERSION)" >&2
47+
exit 1
48+
fi
49+
50+
if git rev-parse --quiet --verify "refs/tags/v$VERSION" >/dev/null; then
51+
echo "Release $VERSION already exists" >&2
52+
exit 1
53+
fi
54+
REMOTE_TAG=$(git ls-remote --tags origin "refs/tags/v$VERSION")
55+
if [[ -n "$REMOTE_TAG" ]]; then
56+
echo "Release $VERSION already exists" >&2
57+
exit 1
58+
fi
59+
60+
git tag -a "v$VERSION" origin/main -m "vscode-liquidjava $VERSION"
61+
git push origin "refs/tags/v$VERSION"
62+
exit 0
63+
fi
64+
65+
if ! command -v gh >/dev/null 2>&1; then
66+
echo "GitHub CLI (gh) is required to create the release pull request" >&2
3367
exit 1
3468
fi
3569

36-
git pull
37-
git add .
70+
if [[ -z "$VERSION" ]]; then
71+
VERSION=$(node -e 'const [major, minor, patch] = require("./client/package.json").version.split(".").map(Number); console.log(`${major}.${minor}.${patch + 1}`)')
72+
fi
73+
74+
CURRENT_VERSION=$(node -p "require('./client/package.json').version")
75+
if [[ "$CURRENT_VERSION" == "$VERSION" ]]; then
76+
echo "Version $VERSION is already on main; choose a new version" >&2
77+
exit 1
78+
fi
79+
80+
BRANCH="codex/release-$VERSION"
81+
if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
82+
echo "Release branch $BRANCH already exists" >&2
83+
exit 1
84+
fi
85+
REMOTE_BRANCH=$(git ls-remote --heads origin "refs/heads/$BRANCH")
86+
if [[ -n "$REMOTE_BRANCH" ]]; then
87+
echo "Release branch $BRANCH already exists" >&2
88+
exit 1
89+
fi
90+
91+
if git rev-parse --quiet --verify "refs/tags/v$VERSION" >/dev/null; then
92+
echo "Release $VERSION already exists" >&2
93+
exit 1
94+
fi
95+
REMOTE_TAG=$(git ls-remote --tags origin "refs/tags/v$VERSION")
96+
if [[ -n "$REMOTE_TAG" ]]; then
97+
echo "Release $VERSION already exists" >&2
98+
exit 1
99+
fi
100+
101+
git switch -c "$BRANCH"
102+
(cd client && npm version "$VERSION" --no-git-tag-version >/dev/null)
103+
git add client/package.json client/package-lock.json
38104
git commit -m "Release $VERSION"
39-
git tag -a "v$VERSION" -m "vscode-liquidjava $VERSION"
105+
git push --set-upstream origin "$BRANCH"
106+
107+
gh pr create \
108+
--base main \
109+
--head "$BRANCH" \
110+
--title "Release $VERSION" \
111+
--body "Prepare version $VERSION for release. Merge this pull request after Checks pass, then run ./release.sh --tag $VERSION from main to publish."
40112

41-
git push
42-
git push --tags
113+
printf 'After the release pull request is merged, run ./release.sh --tag %s from main to publish.\n' "$VERSION"

0 commit comments

Comments
 (0)