Skip to content

PHPC-1674: Automate Driver Releases #1538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4fd5ef4
Add script to update version number in phongo_version.h
alcaeus Apr 11, 2024
4f539b6
Add support for release notes in prep_release.php
alcaeus Apr 11, 2024
8e27e9f
Add workflow to create PECL package for tags
alcaeus Apr 18, 2024
7158423
Use PECL-compatible stability suffixes in version
alcaeus Apr 18, 2024
0df9e50
Add dummy changelog for branch packages
alcaeus Apr 18, 2024
2a9bf9a
Use package version from phongo_version.h for install
alcaeus Apr 18, 2024
25acaf8
Disable install step as it currently fails
alcaeus Apr 18, 2024
1c49d08
Upload release artifact for tags
alcaeus Apr 18, 2024
5ef1c98
Extract linux build to action
alcaeus Apr 18, 2024
26bc929
Simplify Windows builds
alcaeus Apr 18, 2024
ea94be3
Remove branch build trigger
alcaeus Apr 18, 2024
76c3f33
Fix errors in packaging workflow
alcaeus Apr 19, 2024
63a5d46
Add release workflow
alcaeus Apr 19, 2024
d800bba
Update release message
alcaeus Apr 24, 2024
4302cda
Write changelog file for PECL package
alcaeus Apr 24, 2024
d6648cb
Add more output to build step
alcaeus Apr 24, 2024
88d08de
Update release documentation
alcaeus Apr 24, 2024
d4b579d
Fix reading changelog for PECL packaging
alcaeus Apr 25, 2024
666a988
Remove explicit phpize installation
alcaeus Apr 29, 2024
2833a36
Remove unnecessary fetch-depth usage
alcaeus Apr 29, 2024
5c46fb3
Use script parameter instead of hardcoded changelog file name
alcaeus Apr 29, 2024
6972709
Improve update-release-version command names
alcaeus Apr 29, 2024
067f691
Remove obsolete comment
alcaeus Apr 29, 2024
5843f69
Update JIRA version field description
alcaeus Apr 29, 2024
f60cd9a
Update release documentation
alcaeus Apr 29, 2024
2a4f512
Install PECL package to ensure it's functional
alcaeus Apr 29, 2024
65d64d0
Only install required extensions
alcaeus Apr 29, 2024
08621e7
Use GFM note syntax
alcaeus May 2, 2024
090fce6
Extract release documentation
alcaeus May 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/arginfo-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
tools: "phpize"

- name: "Run phpize"
run: phpize
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
tools: "phpize"

- name: "Configure driver"
run: .github/workflows/configure.sh
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/linux/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Linux Build"
description: "Builds the driver"
inputs:
version:
description: "PHP version to build for"
required: true
runs:
using: composite
steps:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ inputs.version }}"
# Only install required extensions
extensions: "none,date,json,spl,standard,xml"

- name: "Configure driver"
run: .github/workflows/configure.sh
shell: bash

- name: "Build driver"
run: "make all"
shell: bash
110 changes: 110 additions & 0 deletions .github/workflows/package-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: "Package Release"
run-name: "Package Release ${{ github.ref_name }}"

on:
push:
tags:
- "*"

jobs:
build-pecl:
name: "Create PECL package"
runs-on: "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
# Manually specify a ref. When actions/checkout is run for a tag without a ref, it looks up the underlying
# commit and specifically fetches this to the refs/tags/<tag> ref, which denies us access to the tag message
ref: ${{ github.ref }}
submodules: true

- name: "Build Driver"
uses: ./.github/workflows/linux/build
with:
version: "8.3"

- name: "Write changelog file for packaging"
run: git tag -l ${{ github.ref_name }} --format='%(contents)' > changelog

# This will fill in the release notes from the previously generated changelog
- name: "Build package.xml"
run: "make package.xml RELEASE_NOTES_FILE=$(pwd)/changelog"

- name: "Build release archive"
run: "make package"

# PECL always uses the version for the package name.
# Read it from the version file and store in env to use when uploading artifacts
- name: "Read current package version"
run: echo "PACKAGE_VERSION=$(./bin/update-release-version.php get-version)" >> "$GITHUB_ENV"

- name: "Install release archive to verify correctness"
run: sudo pecl install mongodb-${{ env.PACKAGE_VERSION }}.tgz

- name: "Upload artifact"
uses: actions/upload-artifact@v4
with:
name: mongodb-${{ env.PACKAGE_VERSION }}.tgz
path: mongodb-${{ env.PACKAGE_VERSION }}.tgz
retention-days: 3

- name: "Upload release artifact"
run: gh release upload ${{ github.ref_name }} mongodb-${{ env.PACKAGE_VERSION }}.tgz
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-windows:
name: "Create Windows package"
runs-on: windows-2022
defaults:
run:
shell: cmd

strategy:
fail-fast: false
matrix:
# Note: keep this in sync with the Windows matrix in windows-tests.yml
php: [ "7.4", "8.0", "8.1", "8.2", "8.3" ]
arch: [ x64, x86 ]
ts: [ ts, nts ]

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: "Build Driver"
id: build-driver
uses: ./.github/workflows/windows/build
with:
version: ${{ matrix.php }}
arch: ${{ matrix.arch }}
ts: ${{ matrix.ts }}

- name: "Copy DLL and PDB files to CWD"
run: |
cp %BUILD_DIR%\php_mongodb.dll .
cp %BUILD_DIR%\php_mongodb.pdb .
env:
BUILD_DIR: ${{ steps.build-driver.outputs.build-dir }}

- name: "Upload DLL and PDB files as build artifacts"
uses: actions/upload-artifact@v4
with:
name: php_mongodb-${{ github.ref_name }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
path: |
php_mongodb.dll
php_mongodb.pdb
retention-days: 3

- name: "Create and upload release artifact"
run: |
set ARCHIVE=php_mongodb-${{ github.ref_name }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}.zip
zip %ARCHIVE% php_mongodb.dll php_mongodb.pdb CREDITS CONTRIBUTING.md LICENSE README.md THIRD_PARTY_NOTICES
gh release upload ${{ github.ref_name }} %ARCHIVE%
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139 changes: 139 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: "Release New Version"
run-name: "Release ${{ inputs.version }}"

on:
workflow_dispatch:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workflow_dispatch allows a manual trigger by anyone with write access to the repository. If we want to limit the number of people that can start a release, we'd have to add checks in this workflow, but I don't think that's necessary at this point.

inputs:
version:
description: "The version to be released. This is checked for consistency with the branch name and configuration"
required: true
type: "string"
jira-version-number:
description: "JIRA version ID (e.g. 54321)"
required: true
type: "string"

env:
# TODO: Use different token
GH_TOKEN: ${{ secrets.MERGE_UP_TOKEN }}
GIT_AUTHOR_NAME: "DBX PHP Release Bot"
GIT_AUTHOR_EMAIL: "[email protected]"
default-release-message: |
The PHP team is happy to announce that version {0} of the [mongodb](https://pecl.php.net/package/mongodb) PHP extension is now available on PECL.

**Release Highlights**

TODO: one or more paragraphs describing important changes in this release

A complete list of resolved issues in this release may be found in [JIRA](https://jira.mongodb.org/secure/ReleaseNote.jspa?version={1}&projectId=12484).

**Documentation**

Documentation is available on [PHP.net](https://php.net/set.mongodb).

**Installation**

You can either download and install the source manually, or you can install the extension with:

```
pecl install mongodb-{0}
```

or update with:

```
pecl upgrade mongodb-{0}
```

Windows binaries are attached to the GitHub release notes.

jobs:
prepare-release:
name: "Prepare release"
runs-on: ubuntu-latest

steps:
- name: "Create release output"
run: echo '🎬 Release process for version ${{ inputs.version }} started by @${{ github.triggering_actor }}' >> $GITHUB_STEP_SUMMARY

- uses: actions/checkout@v4
with:
submodules: true
token: ${{ env.GH_TOKEN }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"

- name: "Update version information to stable release"
run: ./bin/update-release-version.php to-stable

- name: "Read current package version"
run: echo "PACKAGE_VERSION=$(./bin/update-release-version.php get-version)" >> "$GITHUB_ENV"

# Sanity check - the version from the input and the one determined by phongo_version.h need to be the same
- name: "Check version for consistency"
if: ${{ inputs.version != env.PACKAGE_VERSION }}
# We exit with an error to abort the workflow. This is only run if the versions don't match
run: |
echo '❌ Release failed due to version mismatch: expected ${{ inputs.version }}, got ${{ env.PACKAGE_VERSION }} from code' >> $GITHUB_STEP_SUMMARY
exit 1

#
# Preliminary checks done - commence the release process
#

- name: "Set git author information"
run: |
git config user.name "${GIT_AUTHOR_NAME}"
git config user.email "${GIT_AUTHOR_EMAIL}"

# Create the "Package x.y.z" commit that will be the base of our tag
- name: "Create release commit"
run: git commit -m "Package ${{ env.PACKAGE_VERSION }}" phongo_version.h

# Create a draft release with a changelog
# TODO: Consider using the API to generate changelog
- name: "Create draft release with generated changelog"
run: gh release create ${{ env.PACKAGE_VERSION }} --target ${{ github.ref_name }} --generate-notes --draft

- name: "Read changelog from draft release"
run: gh release view ${{ env.PACKAGE_VERSION }} --json body --template '{{ .body }}' >> changelog

# TODO: Sign tag
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be done in a later step as we currently don't have the signing infrastructure in place.

- name: "Create release tag"
run: git tag -a -F changelog ${{ env.PACKAGE_VERSION }}

- name: "Update version information to next patch development release"
run: |
./bin/update-release-version.php to-next-patch-dev
git commit -m "Back to -dev" phongo_version.h

# TODO: Manually merge using ours strategy. This avoids merge-up pull requests being created
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer this to a separate PR as it requires some work to make this logic from the merge-up action reusable here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to ticket this if needed so we don't lose track of it.

I assume we already have a ticket to track the earlier TODO for release signing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Process is:
# 1. switch to next branch (according to merge-up action)
# 2. merge release branch using --strategy=ours
# 3. push next branch
# 4. switch back to release branch, then push

- name: "Push changes from release branch"
run: git push

- name: "Prepare release message"
run: |
echo "${{ format(env.default-release-message, env.PACKAGE_VERSION, inputs.jira-version-number) }}" > release-message
cat changelog >> release-message

# Update release with correct release information
- name: "Update release information"
run: echo "RELEASE_URL=$(gh release edit ${{ env.PACKAGE_VERSION }} --title "${{ env.PACKAGE_VERSION }}" --notes-file release-message)" >> "$GITHUB_ENV"

# Pushing the release tag starts build processes that then produce artifacts for the release
- name: "Push release tag"
run: git push origin ${{ env.PACKAGE_VERSION }}

- name: "Set summary"
run: |
echo '🚀 Created tag and drafted release for version [${{ inputs.version }}](${{ env.RELEASE_URL }})' >> $GITHUB_STEP_SUMMARY
echo '✍️ You may now update the release notes and publish the release when ready' >> $GITHUB_STEP_SUMMARY
15 changes: 4 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
fetch-depth: 2
submodules: true

- id: setup-mongodb
Expand All @@ -63,17 +62,11 @@ jobs:
version: ${{ matrix.mongodb-version }}
topology: ${{ matrix.topology }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
- name: "Build Driver"
id: build-driver
uses: ./.github/workflows/linux/build
with:
php-version: "${{ matrix.php-version }}"
tools: "phpize"

- name: "Configure driver"
run: .github/workflows/configure.sh

- name: "Build driver"
run: "make all"
version: ${{ matrix.php-version }}

- name: "Run Tests"
run: TEST_PHP_ARGS="-q -x --show-diff -g FAIL,XFAIL,BORK,WARN,LEAK,SKIP" make test
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/windows-release-build.yml

This file was deleted.

Loading