Skip to content

Commit afbc160

Browse files
authored
PHPLIB-583: Automate release process (#1288)
* PHPLIB-583: Automate release process * Remove automatically generated changelog from release * Add release integrity section to readme
1 parent 189700f commit afbc160

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

.github/workflows/release.yml

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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 release message filled in
84+
- name: "Prepare release message"
85+
run: |
86+
cat > release-message <<'EOL'
87+
${{ format(env.default-release-message, inputs.version, inputs.jira-version-number) }}
88+
EOL
89+
90+
- name: "Create draft release"
91+
run: echo "RELEASE_URL=$(gh release create ${{ inputs.version }} --target ${{ github.ref_name }} --title "${{ inputs.version }}" --notes-file release-message --draft)" >> "$GITHUB_ENV"
92+
93+
# This step creates the signed release tag
94+
- name: "Create release tag"
95+
uses: mongodb-labs/drivers-github-tools/garasign/git-sign@main
96+
with:
97+
command: "git tag -m 'Release ${{ inputs.version }}' -s --local-user=${{ vars.GPG_KEY_ID }} ${{ inputs.version }}"
98+
garasign_username: ${{ secrets.GRS_CONFIG_USER1_USERNAME }}
99+
garasign_password: ${{ secrets.GRS_CONFIG_USER1_PASSWORD }}
100+
artifactory_username: ${{ secrets.ARTIFACTORY_USER }}
101+
artifactory_password: ${{ secrets.ARTIFACTORY_PASSWORD }}
102+
103+
# TODO: Manually merge using ours strategy. This avoids merge-up pull requests being created
104+
# Process is:
105+
# 1. switch to next branch (according to merge-up action)
106+
# 2. merge release branch using --strategy=ours
107+
# 3. push next branch
108+
# 4. switch back to release branch, then push
109+
110+
- name: "Push changes from release branch"
111+
run: git push
112+
113+
- name: "Prepare release message"
114+
run: |
115+
cat > release-message <<'EOL'
116+
${{ format(env.default-release-message, inputs.version, inputs.jira-version-number) }}
117+
EOL
118+
cat changelog >> release-message
119+
120+
# Pushing the release tag starts build processes that then produce artifacts for the release
121+
- name: "Push release tag"
122+
run: git push origin ${{ inputs.version }}
123+
124+
- name: "Set summary"
125+
run: |
126+
echo '🚀 Created tag and drafted release for version [${{ inputs.version }}](${{ env.RELEASE_URL }})' >> $GITHUB_STEP_SUMMARY
127+
echo '✍️ You may now update the release notes and publish the release when ready' >> $GITHUB_STEP_SUMMARY

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ that the `mongodb` extension be installed:
4444
Additional installation instructions for the extension may be found in its
4545
[PHP.net documentation](https://php.net/manual/en/mongodb.installation.php).
4646

47+
## Release Integrity
48+
49+
Releases are created automatically and the resulting release tag is signed using
50+
the [PHP team's GPG key](https://pgp.mongodb.com/php-driver.asc). To verify the
51+
tag signature, download the key and import it using `gpg`:
52+
53+
```shell
54+
gpg --import php-driver.asc
55+
```
56+
57+
Then, in a local clone, verify the signature of a given tag (e.g. `1.19.0`):
58+
59+
```shell
60+
git show --show-signature 1.19.0
61+
```
62+
63+
> [!NOTE]
64+
> Composer does not support verifying signatures as part of its installation
65+
> process.
66+
4767
## Reporting Issues
4868

4969
Issues pertaining to the library should be reported in the

0 commit comments

Comments
 (0)