Skip to content

Commit d8e04aa

Browse files
committed
PHPLIB-583: Automate release process
1 parent 189700f commit d8e04aa

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

.github/workflows/release.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: "Release New Version"
2+
run-name: "Release ${{ inputs.version }}"
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: "The version to be released. This is checked for consistency with the branch name and configuration"
9+
required: true
10+
type: "string"
11+
jira-version-number:
12+
description: "JIRA version ID (e.g. 54321)"
13+
required: true
14+
type: "string"
15+
16+
env:
17+
# TODO: Use different token
18+
GH_TOKEN: ${{ secrets.MERGE_UP_TOKEN }}
19+
GIT_AUTHOR_NAME: "DBX PHP Release Bot"
20+
GIT_AUTHOR_EMAIL: "[email protected]"
21+
default-release-message: |
22+
The PHP team is happy to announce that version {0} of the MongoDB PHP library is now available.
23+
24+
**Release Highlights**
25+
26+
TODO: one or more paragraphs describing important changes in this release
27+
28+
A complete list of resolved issues in this release may be found in [JIRA](https://jira.mongodb.org/secure/ReleaseNote.jspa?version={1}&projectId=12483).
29+
30+
**Documentation**
31+
32+
Documentation for this library may be found in the [PHP Library Manual](https://mongodb.com/docs/php-library/current/).
33+
34+
**Installation**
35+
36+
This library may be installed or upgraded with:
37+
38+
composer require mongodb/mongodb:{0}
39+
40+
Installation instructions for the `mongodb` extension may be found in the [PHP.net documentation](https://php.net/manual/en/mongodb.installation.php).
41+
42+
jobs:
43+
prepare-release:
44+
name: "Prepare release"
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: "Create release output"
49+
run: echo '🎬 Release process for version ${{ inputs.version }} started by @${{ github.triggering_actor }}' >> $GITHUB_STEP_SUMMARY
50+
51+
- uses: actions/checkout@v4
52+
with:
53+
submodules: true
54+
token: ${{ env.GH_TOKEN }}
55+
56+
- name: "Store version numbers in env variables"
57+
run: |
58+
echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV
59+
echo RELEASE_BRANCH=v$(echo ${{ inputs.version }} | cut -d '.' -f-2) >> $GITHUB_ENV
60+
61+
- name: "Ensure release tag does not already exist"
62+
run: |
63+
if [[ $(git tag -l ${RELEASE_VERSION}) == ${RELEASE_VERSION} ]]; then
64+
echo '❌ Release failed: tag for version ${{ inputs.version }} already exists' >> $GITHUB_STEP_SUMMARY
65+
exit 1
66+
fi
67+
68+
- name: "Fail if branch names don't match"
69+
if: ${{ github.ref_name != env.RELEASE_BRANCH }}
70+
run: |
71+
echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
72+
exit 1
73+
74+
#
75+
# Preliminary checks done - commence the release process
76+
#
77+
78+
- name: "Set git author information"
79+
run: |
80+
git config user.name "${GIT_AUTHOR_NAME}"
81+
git config user.email "${GIT_AUTHOR_EMAIL}"
82+
83+
# Create a draft release with a changelog
84+
# TODO: Consider using the API to generate changelog
85+
- name: "Create draft release with generated changelog"
86+
run: gh release create ${{ inputs.version }} --target ${{ github.ref_name }} --generate-notes --draft
87+
88+
- name: "Read changelog from draft release"
89+
run: gh release view ${{ inputs.version }} --json body --template '{{ .body }}' >> changelog
90+
91+
- name: "Prepare tag message"
92+
run: |
93+
echo -e "Release ${PACKAGE_VERSION}\n" > tag-message
94+
cat changelog >> tag-message
95+
96+
# This step creates the signed release tag
97+
- name: "Create release tag"
98+
uses: mongodb-labs/drivers-github-tools/garasign/git-sign@main
99+
with:
100+
command: "git tag -F tag-message -s --local-user=${{ vars.GPG_KEY_ID }} ${{ inputs.version }}"
101+
garasign_username: ${{ secrets.GRS_CONFIG_USER1_USERNAME }}
102+
garasign_password: ${{ secrets.GRS_CONFIG_USER1_PASSWORD }}
103+
artifactory_username: ${{ secrets.ARTIFACTORY_USER }}
104+
artifactory_password: ${{ secrets.ARTIFACTORY_PASSWORD }}
105+
106+
# TODO: Manually merge using ours strategy. This avoids merge-up pull requests being created
107+
# Process is:
108+
# 1. switch to next branch (according to merge-up action)
109+
# 2. merge release branch using --strategy=ours
110+
# 3. push next branch
111+
# 4. switch back to release branch, then push
112+
113+
- name: "Push changes from release branch"
114+
run: git push
115+
116+
- name: "Prepare release message"
117+
run: |
118+
cat > release-message <<'EOL'
119+
${{ format(env.default-release-message, inputs.version, inputs.jira-version-number) }}
120+
EOL
121+
cat changelog >> release-message
122+
123+
# Update release with correct release information
124+
- name: "Update release information"
125+
run: echo "RELEASE_URL=$(gh release edit ${{ inputs.version }} --title "${{ inputs.version }}" --notes-file release-message)" >> "$GITHUB_ENV"
126+
127+
# Pushing the release tag starts build processes that then produce artifacts for the release
128+
- name: "Push release tag"
129+
run: git push origin ${{ inputs.version }}
130+
131+
- name: "Set summary"
132+
run: |
133+
echo '🚀 Created tag and drafted release for version [${{ inputs.version }}](${{ env.RELEASE_URL }})' >> $GITHUB_STEP_SUMMARY
134+
echo '✍️ You may now update the release notes and publish the release when ready' >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)