44 push :
55 tags :
66 - ' *'
7+ branches :
8+ - master
79
810jobs :
911 build :
@@ -12,50 +14,74 @@ jobs:
1214 steps :
1315 - uses : actions/checkout@v4
1416
15- - name : Extract tag name
16- id : extract_tag
17+ - name : Determine trigger type
18+ id : trigger_type
1719 run : |
18- TAG=${GITHUB_REF#refs/tags/}
19- echo "tag=$TAG" >> $GITHUB_OUTPUT
20- echo "Extracted tag: $TAG"
20+ if [[ "${{ github.ref }}" == refs/tags/* ]]; then
21+ echo "is_tag=true" >> $GITHUB_OUTPUT
22+ echo "is_dry_run=false" >> $GITHUB_OUTPUT
23+ TAG=${GITHUB_REF#refs/tags/}
24+ echo "tag=$TAG" >> $GITHUB_OUTPUT
25+ echo "Triggered by tag: $TAG"
26+ else
27+ echo "is_tag=false" >> $GITHUB_OUTPUT
28+ echo "is_dry_run=true" >> $GITHUB_OUTPUT
29+ PACKAGE_VERSION=$(node -p "require('./package.json').version")
30+ echo "tag=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
31+ echo "Triggered by master branch push (dry-run mode)"
32+ echo "Using version from package.json: $PACKAGE_VERSION"
33+ fi
2134
2235 - name : Validate tag format and determine release type
2336 id : validate_tag
2437 run : |
25- TAG="${{ steps.extract_tag.outputs.tag }}"
38+ TAG="${{ steps.trigger_type.outputs.tag }}"
39+ IS_DRY_RUN="${{ steps.trigger_type.outputs.is_dry_run }}"
2640
2741 # Check if tag matches stable release pattern (e.g., 1.0.3)
2842 if echo "$TAG" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
2943 echo "is_stable_release=true" >> $GITHUB_OUTPUT
3044 echo "is_prerelease=false" >> $GITHUB_OUTPUT
3145 echo "should_publish=true" >> $GITHUB_OUTPUT
32- echo "Tag is a stable release: $TAG"
46+ if [ "$IS_DRY_RUN" == "true" ]; then
47+ echo "Dry-run: Tag is a stable release pattern: $TAG"
48+ else
49+ echo "Tag is a stable release: $TAG"
50+ fi
3351 # Check if tag matches pre-release pattern (e.g., 1.0.3-alpha, 1.0.3-beta, 1.0.3-rc.1)
3452 elif echo "$TAG" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-.+$'; then
3553 echo "is_stable_release=false" >> $GITHUB_OUTPUT
3654 echo "is_prerelease=true" >> $GITHUB_OUTPUT
3755 echo "should_publish=true" >> $GITHUB_OUTPUT
38- echo "Tag is a pre-release: $TAG"
56+ if [ "$IS_DRY_RUN" == "true" ]; then
57+ echo "Dry-run: Tag is a pre-release pattern: $TAG"
58+ else
59+ echo "Tag is a pre-release: $TAG"
60+ fi
3961 else
4062 echo "is_stable_release=false" >> $GITHUB_OUTPUT
4163 echo "is_prerelease=false" >> $GITHUB_OUTPUT
4264 echo "should_publish=false" >> $GITHUB_OUTPUT
43- echo "Tag does not match release patterns: $TAG"
65+ if [ "$IS_DRY_RUN" == "true" ]; then
66+ echo "Dry-run: Tag does not match release patterns: $TAG"
67+ else
68+ echo "Tag does not match release patterns: $TAG"
69+ fi
4470 echo "Will only run build and test."
4571 fi
4672
4773 - name : Extract version from tag
4874 id : extract_version
4975 if : steps.validate_tag.outputs.should_publish == 'true'
5076 run : |
51- TAG="${{ steps.extract_tag .outputs.tag }}"
77+ TAG="${{ steps.trigger_type .outputs.tag }}"
5278 # Extract the version number (e.g., 1.0.3 from 1.0.3 or 1.0.3-alpha)
5379 VERSION=$(echo "$TAG" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
5480 echo "version=$VERSION" >> $GITHUB_OUTPUT
5581 echo "Extracted version: $VERSION"
5682
5783 - name : Check version consistency with package.json
58- if : steps.validate_tag.outputs.should_publish == 'true'
84+ if : steps.validate_tag.outputs.should_publish == 'true' && steps.trigger_type.outputs.is_tag == 'true'
5985 run : |
6086 TAG_VERSION="${{ steps.extract_version.outputs.version }}"
6187 PACKAGE_VERSION=$(node -p "require('./package.json').version")
@@ -87,21 +113,85 @@ jobs:
87113 - name : Build VSIX
88114 run : vsce package
89115
90- - name : Publish to VS Code Marketplace
116+ - name : Check if version exists in VS Code Marketplace
117+ id : check_marketplace
91118 if : steps.validate_tag.outputs.should_publish == 'true'
119+ continue-on-error : true
120+ run : |
121+ EXTENSION_ID="royenheart.ege"
122+ VERSION="${{ steps.extract_version.outputs.version }}"
123+
124+ echo "Checking if version $VERSION exists in VS Code Marketplace..."
125+
126+ # Query the marketplace API
127+ RESPONSE=$(curl -s "https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery" \
128+ -H "Content-Type: application/json" \
129+ -H "Accept: application/json;api-version=3.0-preview.1" \
130+ -d "{\"filters\":[{\"criteria\":[{\"filterType\":7,\"value\":\"$EXTENSION_ID\"}]}],\"flags\":914}")
131+
132+ # Check if the specific version exists
133+ VERSION_EXISTS=$(echo "$RESPONSE" | grep -o "\"version\":\"$VERSION\"" || echo "")
134+
135+ if [ -n "$VERSION_EXISTS" ]; then
136+ echo "exists=true" >> $GITHUB_OUTPUT
137+ echo "⚠️ Warning: Version $VERSION already exists in VS Code Marketplace"
138+ else
139+ echo "exists=false" >> $GITHUB_OUTPUT
140+ echo "✓ Version $VERSION does not exist in VS Code Marketplace"
141+ fi
142+
143+ - name : Warn if version exists (dry-run)
144+ if : steps.trigger_type.outputs.is_dry_run == 'true' && steps.validate_tag.outputs.should_publish == 'true' && steps.check_marketplace.outputs.exists == 'true'
145+ run : |
146+ echo "::warning::Version ${{ steps.extract_version.outputs.version }} already exists in VS Code Marketplace. If you create a tag for this version, the marketplace publish will be skipped."
147+
148+ - name : Publish to VS Code Marketplace
149+ id : publish_marketplace
150+ if : steps.validate_tag.outputs.should_publish == 'true' && steps.trigger_type.outputs.is_dry_run == 'false'
151+ continue-on-error : true
92152 env :
93153 VSCE_PAT : ${{ secrets.MS_STORE_TOKEN }}
94154 run : |
155+ set +e # Don't exit on error
95156 if [ "${{ steps.validate_tag.outputs.is_stable_release }}" == "true" ]; then
96157 echo "Publishing as stable release to VS Code Marketplace..."
97- vsce publish -p $VSCE_PAT
158+ vsce publish -p $VSCE_PAT 2>&1 | tee publish_output.txt
98159 else
99160 echo "Publishing as pre-release to VS Code Marketplace..."
100- vsce publish --pre-release -p $VSCE_PAT
161+ vsce publish --pre-release -p $VSCE_PAT 2>&1 | tee publish_output.txt
101162 fi
163+ echo "exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
164+ exit ${PIPESTATUS[0]}
165+
166+ - name : Check marketplace publish result
167+ if : steps.validate_tag.outputs.should_publish == 'true' && steps.trigger_type.outputs.is_dry_run == 'false'
168+ run : |
169+ if [ "${{ steps.publish_marketplace.outcome }}" == "failure" ]; then
170+ # Check if the error output contains "already exists"
171+ if [ -f publish_output.txt ] && grep -q "already exists" publish_output.txt; then
172+ echo "::warning::Version ${{ steps.extract_version.outputs.version }} already exists in VS Code Marketplace. This version may have been published manually. Skipping marketplace publish."
173+ else
174+ echo "::error::Failed to publish to VS Code Marketplace for an unknown reason."
175+ if [ -f publish_output.txt ]; then
176+ echo "Error details:"
177+ cat publish_output.txt
178+ fi
179+ exit 1
180+ fi
181+ else
182+ echo "✓ Successfully published to VS Code Marketplace"
183+ fi
184+
185+ - name : Upload VSIX as artifact (dry-run)
186+ if : steps.trigger_type.outputs.is_dry_run == 'true'
187+ uses : actions/upload-artifact@v4
188+ with :
189+ name : vscode-ege-${{ steps.trigger_type.outputs.tag }}
190+ path : ./*.vsix
191+ retention-days : 30
102192
103193 - name : Create GitHub Release
104- if : steps.validate_tag.outputs.should_publish == 'true'
194+ if : steps.validate_tag.outputs.should_publish == 'true' && steps.trigger_type.outputs.is_dry_run == 'false'
105195 uses : softprops/action-gh-release@v2
106196 with :
107197 files : ./*.vsix
0 commit comments