Skip to content

Commit ede5222

Browse files
chore: add ovsx sync workflows (#2)
1 parent 9b6dc00 commit ede5222

File tree

4 files changed

+242
-0
lines changed

4 files changed

+242
-0
lines changed

.github/workflows/auto-tag.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
10+
concurrency:
11+
group: auto-tag-${{ github.ref }}
12+
cancel-in-progress: false
13+
14+
jobs:
15+
tag-version:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
env:
20+
EXTENSION_PATH: packages/vscode-tailwindcss
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
# Reads package.json, calculates the expected tag format (vX.Y.Z), and outputs it.
27+
# We need to know the current version in package.json to determine if a tag is missing.
28+
- name: Get Version and Tag
29+
id: version
30+
run: |
31+
cd ${{ env.EXTENSION_PATH }} || exit 1
32+
VERSION=$(jq -r .version package.json)
33+
34+
if [ "${{ env.EXTENSION_PATH }}" == "." ] || [ "${{ env.EXTENSION_PATH }}" == "./" ]; then
35+
TAG="v$VERSION"
36+
else
37+
# Clean path for tag name (remove leading ./ and trailing /)
38+
CLEAN_PATH=$(echo "${{ env.EXTENSION_PATH }}" | sed 's/^\.\///' | sed 's/\/$//')
39+
TAG="$CLEAN_PATH/v$VERSION"
40+
fi
41+
42+
echo "Detected version: $VERSION"
43+
echo "Calculated tag: $TAG"
44+
echo "tag=$TAG" >> $GITHUB_OUTPUT
45+
46+
# Checks if the calculated tag exists. If not, creates and pushes it.
47+
# This ensures we only create tags that don't exist yet, avoiding errors and duplicate releases.
48+
- name: Check and Push Tag
49+
env:
50+
TAG: ${{ steps.version.outputs.tag }}
51+
run: |
52+
if git rev-parse "$TAG" >/dev/null 2>&1; then
53+
echo "Tag $TAG already exists. Skipping."
54+
else
55+
echo "Tag $TAG does not exist. Creating..."
56+
git config user.name "GitHub Action"
57+
git config user.email "action@github.com"
58+
git tag -a "$TAG" -m "Release $TAG"
59+
git push origin "$TAG"
60+
fi
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
types: [opened, synchronize, reopened]
7+
8+
jobs:
9+
check-version:
10+
runs-on: ubuntu-latest
11+
env:
12+
EXTENSION_PATH: packages/vscode-tailwindcss
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
# Calculates the tag from package.json and checks if it exists in refs/tags/.
19+
# This informs the user if the current version is already tagged, which would prevent a new release.
20+
- name: Check Version Tag
21+
run: |
22+
cd ${{ env.EXTENSION_PATH }} || exit 1
23+
VERSION=$(jq -r .version package.json)
24+
25+
if [ "${{ env.EXTENSION_PATH }}" == "." ] || [ "${{ env.EXTENSION_PATH }}" == "./" ]; then
26+
TAG="v$VERSION"
27+
else
28+
CLEAN_PATH=$(echo "${{ env.EXTENSION_PATH }}" | sed 's/^\.\///' | sed 's/\/$//')
29+
TAG="$CLEAN_PATH/v$VERSION"
30+
fi
31+
32+
echo "Checking for tag: $TAG"
33+
34+
if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
35+
echo "::warning::Tag $TAG already exists! This PR will NOT trigger a release when merged unless the version is bumped."
36+
else
37+
echo "::notice::Tag $TAG does not exist. Merging this PR will trigger a release for version $VERSION."
38+
fi

.github/workflows/release.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This workflow builds and publishes the extension to OpenVSX.
2+
# It runs when a new tag (v*) is pushed.
3+
name: Release to OpenVSX
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
tags:
9+
- "v*"
10+
- "**/v*"
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
env:
16+
EXTENSION_PATH: packages/vscode-tailwindcss
17+
PUBLISHER_NAME: TimsExperiments
18+
OPEN_VSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- uses: pnpm/action-setup@v4
24+
with:
25+
version: 10
26+
27+
- name: Setup Node
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: lts/*
31+
cache: "pnpm"
32+
33+
- name: Install Dependencies
34+
run: pnpm install --frozen-lockfile
35+
36+
- name: Build Everything
37+
run: pnpm -r run build
38+
39+
# Updates the 'publisher' field in package.json to match the environment variable.
40+
# The upstream package.json has the original publisher. We need to publish under YOUR publisher ID.
41+
- name: Patch to ${{ env.PUBLISHER_NAME }}
42+
run: |
43+
cd ${{ env.EXTENSION_PATH }}
44+
45+
jq '.publisher = "${{ env.PUBLISHER_NAME }}"' package.json > package.json.tmp && mv package.json.tmp package.json
46+
47+
echo "Publisher verified as:"
48+
grep '"publisher":' package.json
49+
50+
# Runs 'vsce package' to create the file and 'ovsx publish' to upload it.
51+
# This creates the .vsix artifact and uploads it to the OpenVSX registry.
52+
- name: Build & Publish
53+
env:
54+
OVSX_PAT: ${{ env.OPEN_VSX_TOKEN }}
55+
run: |
56+
cd ${{ env.EXTENSION_PATH }}
57+
58+
pnpm dlx vsce package
59+
60+
pnpm dlx ovsx publish -p $OVSX_PAT || echo "Publish failed or version already exists."

.github/workflows/sync.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This workflow keeps your fork in sync with the upstream repository.
2+
# It runs on a schedule (daily) or can be triggered manually.
3+
name: Sync Upstream
4+
5+
on:
6+
schedule:
7+
- cron: "0 3 * * *" # Runs at 3 AM UTC daily
8+
workflow_dispatch:
9+
10+
jobs:
11+
sync-pr:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Configure Git
23+
run: |
24+
git config --global user.name 'GitHub Action'
25+
git config --global user.email 'action@github.com'
26+
27+
# Uses 'gh repo view' to find the parent repository URL and default branch.
28+
# This identifies the source repository we forked from, so we know where to pull changes from.
29+
- name: Detect Upstream Repository
30+
id: upstream
31+
env:
32+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
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
38+
echo "Error: This repository is not a fork. Cannot sync."
39+
exit 1
40+
fi
41+
42+
echo "Detected upstream: $PARENT_URL"
43+
44+
git remote add upstream $PARENT_URL
45+
git fetch upstream
46+
47+
# Detect upstream default branch (main vs master)
48+
DEFAULT_BRANCH=$(git remote show upstream | grep 'HEAD branch' | cut -d' ' -f5)
49+
echo "Detected upstream default branch: $DEFAULT_BRANCH"
50+
51+
# Output variables for next steps
52+
echo "url=$PARENT_URL" >> $GITHUB_OUTPUT
53+
echo "branch=$DEFAULT_BRANCH" >> $GITHUB_OUTPUT
54+
55+
# Creates a new branch 'upstream-sync', merges upstream changes into it, and pushes to origin.
56+
# This safely merges upstream changes without affecting the main branch immediately (in case of conflicts).
57+
- name: Prepare Merge Branch
58+
env:
59+
TARGET_BRANCH: ${{ steps.upstream.outputs.branch }}
60+
run: |
61+
git checkout -b upstream-sync
62+
63+
# Merge upstream. 'recursive' handles file additions well.
64+
git merge upstream/$TARGET_BRANCH --allow-unrelated-histories -m "chore: sync with upstream"
65+
66+
# Push to your fork (updates PR if exists)
67+
git push --force-with-lease origin upstream-sync
68+
69+
# Opens a PR from 'upstream-sync' to the default branch and enables auto-merge.
70+
# This proposes the changes to the default branch and automatically merges them if checks pass.
71+
- name: Create PR & Auto-Merge
72+
env:
73+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
BASE_BRANCH: ${{ steps.upstream.outputs.branch }}
75+
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

0 commit comments

Comments
 (0)