Skip to content

Commit e00b94c

Browse files
authored
Workflows (#59)
* refactor: streamline publish workflow and improve version change detection * refactor: enhance publish workflow to handle manual triggers and first commits
1 parent 88bd2a8 commit e00b94c

1 file changed

Lines changed: 35 additions & 7 deletions

File tree

.github/workflows/publish.yml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,41 @@ jobs:
2121
- name: Get changed files
2222
id: changed-files
2323
run: |
24-
echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | tr '\n' ' ')" >> $GITHUB_OUTPUT
24+
# Handle different trigger scenarios
25+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
26+
# For manual triggers, compare with previous commit
27+
echo "files=$(git diff --name-only HEAD~1 HEAD | tr '\n' ' ')" >> $GITHUB_OUTPUT
28+
elif [ -z "${{ github.event.before }}" ] || [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
29+
# For first commit or when before is null, get all files in the commit
30+
echo "files=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || git ls-files | tr '\n' ' ')" >> $GITHUB_OUTPUT
31+
else
32+
# Normal push event
33+
echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | tr '\n' ' ')" >> $GITHUB_OUTPUT
34+
fi
2535
2636
- name: Check version change and file types
2737
id: check-changes
2838
run: |
29-
# Check if package.json version changed
30-
VERSION_CHANGED=$(git diff ${{ github.event.before }} ${{ github.event.after }} package.json | grep '+\s*"version"')
39+
# Check if package.json version changed with proper fallback
40+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
41+
# For manual triggers, check if version changed in last commit
42+
VERSION_CHANGED=$(git diff HEAD~1 HEAD package.json | grep -E '^\+\s*"version"' || echo "")
43+
elif [ -z "${{ github.event.before }}" ] || [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
44+
# For first commit or when before is null, assume version changed
45+
VERSION_CHANGED="version_changed_first_commit"
46+
else
47+
# Normal push event
48+
VERSION_CHANGED=$(git diff ${{ github.event.before }} ${{ github.event.after }} package.json | grep -E '^\+\s*"version"' || echo "")
49+
fi
3150
3251
# Get list of changed files
3352
CHANGED_FILES="${{ steps.changed-files.outputs.files }}"
3453
54+
# Debug output
55+
echo "🔍 Event: ${{ github.event_name }}"
56+
echo "📁 Changed files: $CHANGED_FILES"
57+
echo "📦 Version changed: ${VERSION_CHANGED:-'no'}"
58+
3559
# Check if only documentation files were changed
3660
DOCS_ONLY=true
3761
for file in $CHANGED_FILES; do
@@ -44,7 +68,11 @@ jobs:
4468
# Initialize should_publish as false
4569
echo "should_publish=false" >> $GITHUB_OUTPUT
4670
47-
if [[ "$DOCS_ONLY" == "true" ]]; then
71+
# For manual workflow dispatch, always publish (assuming user knows what they're doing)
72+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
73+
echo "🚀 Manual workflow dispatch - proceeding with publish"
74+
echo "should_publish=true" >> $GITHUB_OUTPUT
75+
elif [[ "$DOCS_ONLY" == "true" ]]; then
4876
echo "ℹ️ Only documentation files were changed"
4977
echo "should_publish=false" >> $GITHUB_OUTPUT
5078
elif [[ -z "$VERSION_CHANGED" ]]; then
@@ -119,7 +147,7 @@ jobs:
119147
with:
120148
name: extension-release-v${{ steps.package.outputs.version }}-${{ steps.package.outputs.date }}
121149
path: "*.vsix"
122-
retention-days: 99 # Maximum retention period allowed by GitHub
150+
retention-days: 90 # Maximum retention period allowed by GitHub
123151

124152
- name: Check if tag exists
125153
id: check_tag
@@ -138,9 +166,9 @@ jobs:
138166
timeout_minutes: 5
139167
max_attempts: 3
140168
retry_wait_seconds: 30
141-
command: vsce publish --packagePath ${{ steps.package.outputs.vsix_path }}
169+
command: vsce publish -p $VSC_PAT --packagePath ${{ steps.package.outputs.vsix_path }}
142170
env:
143-
VSCE_PAT: ${{ secrets.VSCE_PAT }}
171+
VSC_PAT: ${{ secrets.VSC_PAT }}
144172

145173
- name: Generate Release Notes
146174
id: release_notes

0 commit comments

Comments
 (0)