Skip to content

Commit 7601587

Browse files
chore: update ovsx sync workflows (#3)
1 parent ede5222 commit 7601587

File tree

5 files changed

+199
-133
lines changed

5 files changed

+199
-133
lines changed

.github/workflows/auto-tag.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow checks if the version in package.json already has a corresponding git tag.
2+
# It runs on Pull Requests.
3+
name: Check Version
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
- master
9+
10+
jobs:
11+
check-version:
12+
runs-on: ubuntu-latest
13+
env:
14+
EXTENSION_PATH: packages/vscode-tailwindcss
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
# Calculates the tag from package.json and checks if it exists in refs/tags/.
21+
# This informs the user if the current version is already tagged, which would prevent a new release.
22+
- name: Check Version Tag
23+
run: |
24+
cd ${{ env.EXTENSION_PATH }} || exit 1
25+
VERSION=$(jq -r .version package.json)
26+
27+
if [ "${{ env.EXTENSION_PATH }}" == "." ] || [ "${{ env.EXTENSION_PATH }}" == "./" ]; then
28+
TAG="v$VERSION"
29+
else
30+
CLEAN_PATH=$(echo "${{ env.EXTENSION_PATH }}" | sed 's/^\.\///' | sed 's/\/$//')
31+
TAG="$CLEAN_PATH/v$VERSION"
32+
fi
33+
34+
echo "Checking for tag: $TAG"
35+
36+
if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
37+
echo "::warning::Tag $TAG already exists! This PR will NOT trigger a release when merged unless the version is bumped."
38+
else
39+
echo "::notice::Tag $TAG does not exist. Merging this PR will trigger a release for version $VERSION."
40+
fi
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# This workflow automatically creates a git tag when a version change is detected in package.json.
2+
# It runs on pushes to the main/master branch.
3+
name: Auto Tag Release
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: auto-tag-${{ github.ref }}
13+
cancel-in-progress: false
14+
15+
jobs:
16+
tag-version:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
outputs:
21+
tag: ${{ steps.version.outputs.tag }}
22+
created: ${{ steps.tag.outputs.created }}
23+
env:
24+
EXTENSION_PATH: packages/vscode-tailwindcss
25+
PUBLISHER_NAME: TimsExperiments
26+
OPEN_VSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
# Reads package.json, calculates the expected tag format (vX.Y.Z), and outputs it.
33+
# We need to know the current version in package.json to determine if a tag is missing.
34+
- name: Get Version and Tag
35+
id: version
36+
run: |
37+
cd ${{ env.EXTENSION_PATH }} || exit 1
38+
VERSION=$(jq -r .version package.json)
39+
40+
if [ "${{ env.EXTENSION_PATH }}" == "." ] || [ "${{ env.EXTENSION_PATH }}" == "./" ]; then
41+
TAG="v$VERSION"
42+
else
43+
# Clean path for tag name (remove leading ./ and trailing /)
44+
CLEAN_PATH=$(echo "${{ env.EXTENSION_PATH }}" | sed 's/^\.\///' | sed 's/\/$//')
45+
TAG="$CLEAN_PATH/v$VERSION"
46+
fi
47+
48+
echo "Detected version: $VERSION"
49+
echo "Calculated tag: $TAG"
50+
echo "tag=$TAG" >> $GITHUB_OUTPUT
51+
52+
# Checks if the calculated tag exists. If not, creates and pushes it.
53+
# This ensures we only create tags that don't exist yet, avoiding errors and duplicate releases.
54+
- name: Check and Push Tag
55+
id: tag
56+
env:
57+
TAG: ${{ steps.version.outputs.tag }}
58+
run: |
59+
if git rev-parse "$TAG" >/dev/null 2>&1; then
60+
echo "Tag $TAG already exists. Skipping."
61+
echo "created=false" >> $GITHUB_OUTPUT
62+
else
63+
echo "Tag $TAG does not exist. Creating..."
64+
git config user.name "GitHub Action"
65+
git config user.email "[email protected]"
66+
git tag -a "$TAG" -m "Release $TAG"
67+
git push origin "$TAG"
68+
echo "created=true" >> $GITHUB_OUTPUT
69+
fi
70+
71+
release:
72+
needs: tag-version
73+
if: needs.tag-version.outputs.created == 'true'
74+
runs-on: ubuntu-latest
75+
env:
76+
EXTENSION_PATH: packages/vscode-tailwindcss
77+
PUBLISHER_NAME: TimsExperiments
78+
OPEN_VSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }}
79+
steps:
80+
- uses: actions/checkout@v4
81+
with:
82+
ref: ${{ needs.tag-version.outputs.tag }}
83+
84+
- name: Detect pnpm version
85+
id: detect-pnpm
86+
run: |
87+
if [ -f package.json ] && grep -q '"packageManager":' package.json; then
88+
echo "packageManager found in package.json"
89+
echo "version=" >> $GITHUB_OUTPUT
90+
else
91+
echo "packageManager not found, using default"
92+
echo "version=10" >> $GITHUB_OUTPUT
93+
fi
94+
95+
- uses: pnpm/action-setup@v4
96+
with:
97+
version: ${{ steps.detect-pnpm.outputs.version }}
98+
99+
- name: Setup Node
100+
uses: actions/setup-node@v4
101+
with:
102+
node-version: lts/*
103+
cache: "pnpm"
104+
105+
- name: Install Dependencies
106+
run: pnpm install --frozen-lockfile
107+
108+
- name: Build Everything
109+
run: pnpm -r run build
110+
111+
# Updates the 'publisher' field in package.json to match the environment variable.
112+
# The upstream package.json has the original publisher. We need to publish under YOUR publisher ID.
113+
- name: Patch to ${{ env.PUBLISHER_NAME }}
114+
run: |
115+
cd ${{ env.EXTENSION_PATH }}
116+
117+
jq '.publisher = "${{ env.PUBLISHER_NAME }}"' package.json > package.json.tmp && mv package.json.tmp package.json
118+
119+
echo "Publisher verified as:"
120+
grep '"publisher":' package.json
121+
122+
# Runs 'vsce package' to create the file and 'ovsx publish' to upload it.
123+
# This creates the .vsix artifact and uploads it to the OpenVSX registry.
124+
- name: Build & Publish
125+
env:
126+
OVSX_PAT: ${{ env.OPEN_VSX_TOKEN }}
127+
run: |
128+
cd ${{ env.EXTENSION_PATH }}
129+
130+
pnpm dlx vsce package
131+
132+
pnpm dlx ovsx publish -p $OVSX_PAT

.github/workflows/sync.yml renamed to .github/workflows/ovsx-fork-tools-sync.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
permissions:
1414
contents: write
1515
pull-requests: write
16+
1617
steps:
1718
- name: Checkout
1819
uses: actions/checkout@v4
@@ -31,14 +32,16 @@ jobs:
3132
env:
3233
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3334
run: |
34-
# Use GitHub CLI to get the parent repository URL
35-
PARENT_URL=$(gh repo view ${{ github.repository }} --json parent --jq '.parent.url')
36-
37-
if [ -z "$PARENT_URL" ] || [ "$PARENT_URL" == "null" ]; then
35+
# Use GitHub CLI to get the parent repository
36+
PARENT_REPO=$(gh repo view ${{ github.repository }} --json parent --jq 'if .parent then (.parent.owner.login + "/" + .parent.name) else null end')
37+
if [ -z "$PARENT_REPO" ] || [ "$PARENT_REPO" == "null" ]; then
3838
echo "Error: This repository is not a fork. Cannot sync."
3939
exit 1
4040
fi
4141
42+
# Get the URL of the parent repository
43+
PARENT_URL=$(gh repo view $PARENT_REPO --json url --jq '.url')
44+
4245
echo "Detected upstream: $PARENT_URL"
4346
4447
git remote add upstream $PARENT_URL
@@ -73,12 +76,23 @@ jobs:
7376
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7477
BASE_BRANCH: ${{ steps.upstream.outputs.branch }}
7578
run: |
76-
gh pr create \
77-
--base $BASE_BRANCH \
78-
--head upstream-sync \
79-
--title "chore: sync with upstream" \
80-
--body "Automated sync from ${{ steps.upstream.outputs.url }}." \
81-
--label "upstream-sync" || echo "PR already exists"
82-
83-
# Enable auto-merge
84-
gh pr merge upstream-sync --auto --merge
79+
# Check if PR already exists
80+
EXISTING_PR=$(gh pr list --head upstream-sync --repo ${{ github.repository }} --json number --jq '.[0].number')
81+
82+
if [ -z "$EXISTING_PR" ]; then
83+
# Create PR only if it doesn't exist
84+
gh pr create \
85+
--base $BASE_BRANCH \
86+
--head upstream-sync \
87+
--repo ${{ github.repository }} \
88+
--title "chore: sync with upstream" \
89+
--body "Automated sync from ${{ steps.upstream.outputs.url }}."
90+
91+
# Get the newly created PR number
92+
PR_NUMBER=$(gh pr list --head upstream-sync --repo ${{ github.repository }} --json number --jq '.[0].number')
93+
else
94+
echo "PR already exists: #$EXISTING_PR"
95+
PR_NUMBER=$EXISTING_PR
96+
fi
97+
98+
echo "✓ PR #$PR_NUMBER is ready for review"

.github/workflows/release.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)