-
Notifications
You must be signed in to change notification settings - Fork 1
128 lines (105 loc) · 4.94 KB
/
bump-version.yml
File metadata and controls
128 lines (105 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Bump Version
on:
workflow_call:
inputs:
version:
description: 'Version to set (YY.MM.DD format)'
required: true
type: string
outputs:
version:
description: 'Version that was set'
value: ${{ jobs.bump.outputs.version }}
version_tag:
description: 'Git tag created'
value: ${{ jobs.bump.outputs.tag }}
branch_name:
description: 'Temporary branch name where version was committed'
value: ${{ jobs.bump.outputs.branch_name }}
jobs:
bump:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.bump.outputs.version }}
tag: ${{ steps.bump.outputs.tag }}
branch_name: ${{ steps.commit.outputs.branch_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # Full history for tagging
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.9.0
- name: Bump version
id: bump
run: |
node .erb/scripts/bump-version.js ${{ inputs.version }}
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
echo "tag=v${{ inputs.version }}" >> $GITHUB_OUTPUT
- name: Create temporary branch and commit
id: commit
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json release/app/package.json
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "⚠️ No changes detected - version already set to v${{ inputs.version }}"
echo "Using current branch: ${{ github.ref_name }}"
# Delete existing tag if present
if git tag -l "v${{ inputs.version }}" | grep -q "v${{ inputs.version }}"; then
git tag -d "v${{ inputs.version }}"
git push origin --delete "v${{ inputs.version }}" 2>/dev/null || true
fi
# Create tag on current commit
git tag -a "v${{ inputs.version }}" \
-m "Release v${{ inputs.version }}" \
-m "Workflow: ${{ github.workflow }}" \
-m "Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
git push origin "v${{ inputs.version }}"
echo "branch_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "✅ Using existing branch: ${{ github.ref_name }}"
else
# Changes detected - create temporary branch
TEMP_BRANCH="tmp-version-${{ inputs.version }}"
echo "📦 Creating temporary branch: $TEMP_BRANCH"
git checkout -b "$TEMP_BRANCH"
git commit -m "chore: bump version to v${{ inputs.version }}
⚠️ TEMPORARY BRANCH - builds will use this
Will merge to main only if draft release succeeds.
🤖 Generated by GitHub Actions
Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
git tag -a "v${{ inputs.version }}" \
-m "Release v${{ inputs.version }}" \
-m "Branch: $TEMP_BRANCH (temporary)" \
-m "Workflow: ${{ github.workflow }}" \
-m "Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
git push origin "$TEMP_BRANCH"
git push origin "v${{ inputs.version }}"
echo "branch_name=$TEMP_BRANCH" >> $GITHUB_OUTPUT
echo "✅ Temporary branch created: $TEMP_BRANCH"
fi
- name: Summary
run: |
BRANCH_NAME="${{ steps.commit.outputs.branch_name }}"
if [[ "$BRANCH_NAME" == tmp-version-* ]]; then
echo "### ✅ Version Bumped (Temporary Branch)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: v${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: $BRANCH_NAME" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: $(git rev-parse HEAD)" >> $GITHUB_STEP_SUMMARY
echo "- **Tag**: v${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "⚠️ **Note**: Temporary branch - will merge to main if draft release succeeds" >> $GITHUB_STEP_SUMMARY
else
echo "### ✅ Version Tag Created" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: v${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: $BRANCH_NAME (no changes needed)" >> $GITHUB_STEP_SUMMARY
echo "- **Tag**: v${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "ℹ️ **Note**: Version already set - using existing branch" >> $GITHUB_STEP_SUMMARY
fi