-
Notifications
You must be signed in to change notification settings - Fork 3
193 lines (158 loc) · 6.18 KB
/
create-connector-release.yaml
File metadata and controls
193 lines (158 loc) · 6.18 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: Automated Release for ndc-nodejs-lambda
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g., v1.20.0)"
required: true
type: string
jobs:
create-release-pr:
name: Create Release PR
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
pull-requests: write
steps:
- name: Validate version format
run: |
VERSION="${{ github.event.inputs.version }}"
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Version must be in format vX.Y.Z (e.g., v1.20.0)"
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check tag doesn't already exist
run: |
if git rev-parse "${{ github.event.inputs.version }}" >/dev/null 2>&1; then
echo "::error::Tag ${{ github.event.inputs.version }} already exists"
exit 1
fi
- name: Check release branch doesn't exist
run: |
BRANCH_NAME="release/${{ github.event.inputs.version }}"
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then
echo "::error::Branch $BRANCH_NAME already exists. Delete it first or use a different version."
exit 1
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Get previous tag
id: get-previous-tag
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
echo "Previous tag: ${PREVIOUS_TAG:-'(none)'}"
- name: Create release branch
run: |
BRANCH_NAME="release/${{ github.event.inputs.version }}"
git checkout -b "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
- name: Generate changelog entry
run: |
VERSION="${{ github.event.inputs.version }}"
VERSION_NO_V="${VERSION#v}"
PREVIOUS_TAG="${{ steps.get-previous-tag.outputs.previous_tag }}"
DATE=$(date +%Y-%m-%d)
# Generate commit log since last tag
if [ -n "$PREVIOUS_TAG" ]; then
echo "Generating changelog from ${PREVIOUS_TAG} to HEAD"
COMMITS=$(git log "${PREVIOUS_TAG}..HEAD" --pretty=format:"- %s" --no-merges | grep -v "^- Release v" || true)
else
echo "No previous tag found, generating full history"
COMMITS=$(git log --pretty=format:"- %s" --no-merges | grep -v "^- Release v" || true)
fi
# Handle empty commits
if [ -z "$COMMITS" ]; then
COMMITS="- No notable changes"
fi
# Create changelog entry
CHANGELOG_ENTRY="## [${VERSION_NO_V}] - ${DATE}
${COMMITS}"
# Create or update CHANGELOG.md
if [ -f CHANGELOG.md ]; then
# Read existing content, skip header line
EXISTING_CONTENT=$(tail -n +2 CHANGELOG.md)
# Write new changelog
{
head -1 CHANGELOG.md
echo ""
echo "$CHANGELOG_ENTRY"
echo ""
echo "$EXISTING_CONTENT"
} > CHANGELOG.tmp
mv CHANGELOG.tmp CHANGELOG.md
else
{
echo "# Changelog"
echo ""
echo "$CHANGELOG_ENTRY"
} > CHANGELOG.md
fi
echo "Generated changelog entry:"
echo "$CHANGELOG_ENTRY"
- name: Update package.json version
working-directory: ./ndc-lambda-sdk
run: |
VERSION="${{ github.event.inputs.version }}"
VERSION_NO_V="${VERSION#v}"
# Update package.json version
npm version "$VERSION_NO_V" --no-git-tag-version
# Regenerate package-lock.json to ensure consistency
npm install --package-lock-only
echo "Updated package.json to version $VERSION_NO_V"
- name: Commit and push changes
run: |
git add CHANGELOG.md ndc-lambda-sdk/package.json ndc-lambda-sdk/package-lock.json
git commit -m "Release ${{ github.event.inputs.version }}"
git push origin "${{ env.branch_name }}"
- name: Generate PR body
id: pr-body
run: |
VERSION="${{ github.event.inputs.version }}"
VERSION_NO_V="${VERSION#v}"
# Extract the changelog section for this version
RELEASE_NOTES=$(awk "/## \[${VERSION_NO_V}\]/{flag=1; next} /## \[/{flag=0} flag" CHANGELOG.md)
cat > pr-body.md << 'EOF'
## Release ${{ github.event.inputs.version }}
This PR prepares the release for version ${{ github.event.inputs.version }}.
### Changes
EOF
echo "$RELEASE_NOTES" >> pr-body.md
cat >> pr-body.md << 'EOF'
### Pre-merge Checklist
- [ ] Review changelog entries for accuracy
- [ ] Verify version in `ndc-lambda-sdk/package.json` is correct
- [ ] Ensure all CI checks pass
### Post-merge Instructions
After merging, create and push the tag to trigger the release workflow:
```bash
git checkout main
git pull origin main
git tag ${{ github.event.inputs.version }}
git push origin ${{ github.event.inputs.version }}
```
> **Note:** The release workflow will automatically publish to npm and create the GitHub release.
EOF
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--base main \
--head "${{ env.branch_name }}" \
--title "Release ${{ github.event.inputs.version }}" \
--body-file pr-body.md \
--label "release"