Skip to content

Commit 32d5ee0

Browse files
committed
PHPLIB-583: Automate release process
1 parent 970d1d3 commit 32d5ee0

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "Sign artifact using garasign"
2+
description: "Signs a release artifact"
3+
inputs:
4+
command:
5+
description: "Command to run inside the container"
6+
required: true
7+
garasign_username:
8+
description: "Garasign username"
9+
required: true
10+
garasign_password:
11+
description: "Garasign password"
12+
required: true
13+
artifactory_username:
14+
description: "Artifactory user"
15+
required: true
16+
artifactory_password:
17+
description: "Artifactory password"
18+
required: true
19+
artifactory_image:
20+
description: "Image to use for artifactory"
21+
default: release-tools-container-registry-local/garasign-git
22+
artifactory_registry:
23+
description: "Artifactory registry to be used"
24+
default: artifactory.corp.mongodb.com
25+
skip_setup:
26+
description: "Whether to skip setup"
27+
default: "false"
28+
29+
runs:
30+
using: composite
31+
steps:
32+
- name: Prepare garasign container
33+
if: ${{ inputs.skip_setup == 'false' }}
34+
uses: ./.github/actions/garasign/setup
35+
with:
36+
garasign_username: ${{ inputs.garasign_username }}
37+
garasign_password: ${{ inputs.garasign_password }}
38+
artifactory_username: ${{ inputs.artifactory_username }}
39+
artifactory_password: ${{ inputs.artifactory_password }}
40+
artifactory_registry: ${{ inputs.artifactory_registry }}
41+
42+
- name: "Run git command"
43+
run: |
44+
podman run \
45+
--env-file=envfile \
46+
--rm \
47+
-v $(pwd):$(pwd) \
48+
-w $(pwd) \
49+
${{ inputs.artifactory_registry }}/${{ inputs.artifactory_image }} \
50+
/bin/bash -c "gpgloader && ${{ inputs.command }}"
51+
shell: bash
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Prepare garasign container"
2+
description: "Prepares the garasign container used to sign artifacts"
3+
inputs:
4+
garasign_username:
5+
description: "Garasign username"
6+
required: true
7+
garasign_password:
8+
description: "Garasign password"
9+
required: true
10+
artifactory_username:
11+
description: "Artifactory user"
12+
required: true
13+
artifactory_password:
14+
description: "Artifactory password"
15+
required: true
16+
artifactory_registry:
17+
description: "Artifactory registry to be used"
18+
default: artifactory.corp.mongodb.com
19+
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Create the envfile
24+
run: |
25+
cat << EOF > envfile
26+
GRS_CONFIG_USER1_USERNAME=${{ inputs.garasign_username }}
27+
GRS_CONFIG_USER1_PASSWORD=${{ inputs.garasign_password }}
28+
EOF
29+
shell: bash
30+
31+
- name: Log in to artifactory
32+
uses: redhat-actions/podman-login@v1
33+
with:
34+
username: ${{ inputs.artifactory_username }}
35+
password: ${{ inputs.artifactory_password }}
36+
registry: ${{ inputs.artifactory_registry }}

.github/workflows/release.yml

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

0 commit comments

Comments
 (0)