Skip to content

Commit 3f91e19

Browse files
ops(KDP): improving release workflows
1 parent 1ccc3f2 commit 3f91e19

File tree

6 files changed

+356
-58
lines changed

6 files changed

+356
-58
lines changed

.github/templates/github/semantic_release/.releaserc.json.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"@semantic-release/github",
88
"@semantic-release/changelog",
99
["@semantic-release/git", {
10-
"assets": ["CHANGELOG.md"]
10+
"assets": ["CHANGELOG.md"],
11+
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
1112
}]
1213
],
1314
"preset": "conventionalcommits",

.github/templates/github/semantic_release/action.yml

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ outputs:
2828
new_release_version:
2929
description: "New TAG attached to the Semantic Release version"
3030
value: ${{ steps.semantic-release.outputs.new_release_version }}
31+
new_release_published:
32+
description: "Whether a new release was published"
33+
value: ${{ steps.semantic-release.outputs.new_release_published }}
3134
new_release_notes:
3235
description: "Release notes for Semantic Release"
33-
value: ${{ env.new_release_notes }}
36+
value: ${{ steps.export-released-notes.outputs.new_release_notes }}
3437

3538
runs:
3639
using: "composite"
@@ -45,18 +48,43 @@ runs:
4548
# populating project specific template for the semantic release
4649
envsubst '${PROJECT_NAME_UPPER} ${PROJECT_NAME_LOWER}' < ${{ inputs.TEMPLATE_FILE }} > ${{ inputs.PROJECT_DIRECTORY }}/.releaserc.json
4750
51+
# Verify the template was created successfully
52+
if [ ! -f "${{ inputs.PROJECT_DIRECTORY }}/.releaserc.json" ]; then
53+
echo "::error::Failed to create .releaserc.json template"
54+
exit 1
55+
fi
56+
57+
# Show the generated template for debugging
58+
echo "Generated semantic-release config:"
59+
cat ${{ inputs.PROJECT_DIRECTORY }}/.releaserc.json
60+
4861
- name: "Setup Node"
4962
uses: actions/setup-node@v3
5063
with:
51-
node-version: 14
64+
node-version: 16
5265

5366
- name: "Configure Git user"
5467
shell: bash
5568
run: |
5669
git config user.email "actions@github.com"
5770
git config user.name "GitHub Actions"
5871
59-
- name: "Semantic Release"
72+
- name: "Install semantic-release dependencies"
73+
shell: bash
74+
run: |
75+
echo "Installing semantic-release dependencies..."
76+
cd ${{ inputs.PROJECT_DIRECTORY }}
77+
npm install --no-package-lock --no-save \
78+
semantic-release@21.0.7 \
79+
@semantic-release/commit-analyzer \
80+
@semantic-release/release-notes-generator \
81+
@semantic-release/changelog \
82+
@semantic-release/github \
83+
@semantic-release/git \
84+
@semantic-release/exec \
85+
conventional-changelog-conventionalcommits@5.0.0
86+
87+
- name: "Run Semantic Release"
6088
id: semantic-release
6189
uses: cycjimmy/semantic-release-action@v3.4.1
6290
env:
@@ -71,44 +99,42 @@ runs:
7199
@semantic-release/changelog
72100
@semantic-release/github
73101
@semantic-release/git
102+
@semantic-release/exec
74103
conventional-changelog-conventionalcommits@5.0.0
75104
76-
- name: "export released version"
105+
- name: "Export released version"
77106
id: export-released-version
78107
shell: bash
79108
run: |
80-
if [ "${{ steps.semantic-release.outputs.new_release_version }}" != "" ] ;
81-
then echo "new_release_version=${{ steps.semantic-release.outputs.new_release_version }}" >> $GITHUB_OUTPUT ;
82-
else if [ "${{ steps.semantic-release.outputs.new_release_version }}" != "" ] ;
83-
then echo "new_release_version=${{ steps.semantic-release.outputs.new_release_version }}" >> $GITHUB_OUTPUT ;
84-
fi ;
109+
if [ "${{ steps.semantic-release.outputs.new_release_version }}" != "" ]; then
110+
echo "new_release_version=${{ steps.semantic-release.outputs.new_release_version }}" >> $GITHUB_OUTPUT
111+
echo "New release version: ${{ steps.semantic-release.outputs.new_release_version }}"
112+
else
113+
echo "No new version released"
85114
fi
86115
87-
- name: "export release notes"
116+
- name: "Export release notes"
88117
id: export-released-notes
89118
shell: bash
90119
run: |
91-
if [ "${{ steps.semantic-release.outputs.new_release_notes }}" != "" ] ; then
92-
RELEASE_NOTES="${{ steps.semantic-release.outputs.new_release_notes }}"
93-
RELEASE_NOTES="${RELEASE_NOTES//'%'/'%25'}"
94-
RELEASE_NOTES="${RELEASE_NOTES//$'\r'/'%0D'}"
95-
RELEASE_NOTES="$(echo "$RELEASE_NOTES" | sed -z 's/\n/\\n/g')"
96-
echo "new_release_notes=${RELEASE_NOTES}" >> $GITHUB_OUTPUT ;
97-
else if [ "${{ steps.semantic-release.outputs.new_release_notes }}" != "" ] ; then
120+
if [ "${{ steps.semantic-release.outputs.new_release_notes }}" != "" ]; then
98121
RELEASE_NOTES="${{ steps.semantic-release.outputs.new_release_notes }}"
99122
RELEASE_NOTES="${RELEASE_NOTES//'%'/'%25'}"
100123
RELEASE_NOTES="${RELEASE_NOTES//$'\r'/'%0D'}"
101-
RELEASE_NOTES="$(echo "$RELEASE_NOTES" | sed -z 's/\n/\\n/g')"
102-
echo "new_release_notes=${RELEASE_NOTES}" >> $GITHUB_OUTPUT ;
103-
fi ;
124+
RELEASE_NOTES="${RELEASE_NOTES//$'\n'/'%0A'}"
125+
echo "new_release_notes=${RELEASE_NOTES}" >> $GITHUB_OUTPUT
126+
echo "Release notes captured successfully"
127+
else
128+
echo "No release notes available"
129+
echo "new_release_notes=No release notes available" >> $GITHUB_OUTPUT
104130
fi
105131
106-
- name: "Do something else when a new release published"
132+
- name: "Release summary"
107133
if: steps.semantic-release.outputs.new_release_published == 'true'
108134
shell: bash
109135
run: |
110-
echo ${{ steps.semantic-release.outputs.new_release_version }}
111-
echo ${{ steps.semantic-release.outputs.new_release_major_version }}
112-
echo ${{ steps.semantic-release.outputs.new_release_minor_version }}
113-
echo ${{ steps.semantic-release.outputs.new_release_patch_version }}
114-
echo ${{ steps.semantic-release.outputs.new_release_patch_version }}
136+
echo "A new release has been published!"
137+
echo "Version: ${{ steps.semantic-release.outputs.new_release_version }}"
138+
echo "Major: ${{ steps.semantic-release.outputs.new_release_major_version }}"
139+
echo "Minor: ${{ steps.semantic-release.outputs.new_release_minor_version }}"
140+
echo "Patch: ${{ steps.semantic-release.outputs.new_release_patch_version }}"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: "Manual Documentation Publish"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
RELEASE_VERSION:
7+
required: true
8+
type: string
9+
description: "Release version for documentation"
10+
UPDATE_LATEST:
11+
required: true
12+
type: boolean
13+
default: true
14+
description: "Update the 'latest' alias to point to this version"
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
UPDATE_DOCS:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
with:
26+
ref: main
27+
fetch-depth: 1
28+
29+
- name: Set up Python
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: 3.11
33+
cache: 'pip'
34+
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install poetry
39+
poetry config virtualenvs.create false
40+
poetry install --only doc --no-interaction
41+
42+
- name: Release documentation with mike
43+
id: deploy_docs
44+
run: |
45+
echo "Deploying documentation for version ${{ inputs.RELEASE_VERSION }}"
46+
47+
git config user.name "${{ github.actor }}"
48+
git config user.email "${{ github.actor }}@users.noreply.github.com"
49+
50+
# Set up command based on whether to update latest alias
51+
if [[ "${{ inputs.UPDATE_LATEST }}" == "true" ]]; then
52+
echo "Updating 'latest' alias to point to version ${{ inputs.RELEASE_VERSION }}"
53+
COMMAND="mike deploy --push --update-aliases ${{ inputs.RELEASE_VERSION }} latest"
54+
else
55+
echo "Not updating 'latest' alias"
56+
COMMAND="mike deploy --push ${{ inputs.RELEASE_VERSION }}"
57+
fi
58+
59+
# Execute the command
60+
$COMMAND
61+
continue-on-error: true
62+
63+
- name: Retry documentation release on failure
64+
if: steps.deploy_docs.outcome == 'failure'
65+
run: |
66+
echo "First documentation deploy attempt failed, retrying..."
67+
sleep 10
68+
git pull --rebase
69+
70+
# Set up command based on whether to update latest alias
71+
if [[ "${{ inputs.UPDATE_LATEST }}" == "true" ]]; then
72+
mike deploy --push --update-aliases ${{ inputs.RELEASE_VERSION }} latest
73+
else
74+
mike deploy --push ${{ inputs.RELEASE_VERSION }}
75+
fi
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "Manual PyPI Publish"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
RELEASE_VERSION:
7+
required: true
8+
type: string
9+
description: "Release version to publish to PyPI"
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
PYPI_PUBLISH:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v3
20+
with:
21+
ref: main
22+
fetch-depth: 1
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: 3.11
28+
cache: 'pip'
29+
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install poetry
34+
poetry config virtualenvs.create false
35+
36+
- name: Install project dependencies
37+
run: |
38+
poetry install --all-extras --no-interaction
39+
40+
- name: Set version for publishing
41+
run: |
42+
echo "Setting package version to ${{ inputs.RELEASE_VERSION }}"
43+
poetry version ${{ inputs.RELEASE_VERSION }}
44+
45+
- name: Build and publish to PyPI
46+
id: publish_pypi
47+
run: |
48+
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
49+
poetry build
50+
poetry publish
51+
env:
52+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
53+
continue-on-error: true
54+
55+
- name: Retry PyPI publish on failure
56+
if: steps.publish_pypi.outcome == 'failure'
57+
run: |
58+
echo "First attempt failed, retrying..."
59+
sleep 10
60+
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
61+
poetry build
62+
poetry publish
63+
env:
64+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}

0 commit comments

Comments
 (0)