Skip to content

Automatic Releases

Automatic Releases #22

# Alternate workflow example.
# This one is identical to the one in release-on-milestone.yml, with one change:
# the Release step uses the ORGANIZATION_ADMIN_TOKEN instead, to allow it to
# trigger a release workflow event. This is useful if you have other actions
# that intercept that event.
name: "Automatic Releases"
on:
milestone:
types:
- "closed"
jobs:
release_parameters:
runs-on: ubuntu-latest
outputs:
version_to_tag: ${{ steps.version_to_tag_step.outputs.version_to_tag }}
previous_semver_version: ${{ steps.previous_semver_version_step.outputs.previous_semver_version }}
ref_for_version_to_tag: ${{ steps.ref_for_version_to_tag_step.outputs.ref_for_version_to_tag }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Version we are making
id: version_to_tag_step
run: |
echo "milestone title = ${{ github.event.milestone.title }}"
echo "version_to_tag=${{ github.event.milestone.title }}" >> $GITHUB_OUTPUT
- name: Previous semver version
id: previous_semver_version_step
run: |
PREVIOUS_SEMVER_VERSION=$(./.github/workflows/get-previous-semver-version.sh ${{ steps.version_to_tag_step.outputs.version_to_tag }})
echo "previous semver version = $PREVIOUS_SEMVER_VERSION"
echo "previous_semver_version=$PREVIOUS_SEMVER_VERSION" >> $GITHUB_OUTPUT
- name: Get the git ref
id: ref_for_version_to_tag_step
run: |
BRANCH_EXTRACT_REGEX="([0-9]+\.[0-9]+)\.[0-9]+"
EXPECTED_BRANCH_NAME="$(echo "${{ steps.version_to_tag_step.outputs.version_to_tag }}" | sed -r -e "s/$BRANCH_EXTRACT_REGEX/\1/").x"
echo "expected branch name = $EXPECTED_BRANCH_NAME"
RELEASE_GIT_SHA=$(git rev-parse origin/$EXPECTED_BRANCH_NAME)
echo "ref for version to be tagged = $RELEASE_GIT_SHA"
echo "ref_for_version_to_tag=$RELEASE_GIT_SHA" >> $GITHUB_OUTPUT
windows-release-build:
needs: [ "release_parameters" ]
strategy:
fail-fast: false
matrix:
php: [ "8.2", "8.1", "8.0", "7.4", "7.3", "7.2", "7.1" ]
arch: [ x64, x86 ]
ts: [ ts, nts ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}
- uses: dawidd6/action-download-artifact@v2
with:
workflow: ci-build.yaml
workflow_conclusion: success
commit: ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}
name: DLL only ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}-${{matrix.php}}-${{matrix.ts}}-${{matrix.arch}}
- name: Get the release version
id: win_get_release_version
run: |
HEADER_RELEASE="$(cat zend_scoutapm.h | grep "PHP_SCOUTAPM_VERSION" | awk '{print $3}' | tr -d '"')"
echo "version=$HEADER_RELEASE" >> $GITHUB_OUTPUT
- name: Prepare zip
run: zip php_scoutapm-${{steps.win_get_release_version.outputs.version}}-${{matrix.php}}-${{matrix.ts}}-${{matrix.arch}}.zip php_scoutapm.dll LICENSE README.md CREDITS
- name: Add zipped DLL as artifact for ${{ needs.release_parameters.outputs.version_to_tag }}
uses: actions/upload-artifact@v3
with:
name: DLL ${{ needs.release_parameters.outputs.version_to_tag }}
path: php_scoutapm-${{steps.win_get_release_version.outputs.version}}-${{matrix.php}}-${{matrix.ts}}-${{matrix.arch}}.zip
pre-verify-release:
name: "Pre-verify release"
needs: [ "release_parameters", "windows-release-build" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}
- name: "Fetch previous release tag from Github API"
uses: octokit/request-action@v2.x
id: get_previous_release_step
with:
route: GET /repos/scoutapp/scout-apm-php-ext/releases/tags/${{ needs.release_parameters.outputs.previous_semver_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Verify that PHP_SCOUTAPM_VERSION has been changed"
run: |
PREVIOUS_RELEASE="${{ fromJson(steps.get_previous_release_step.outputs.data).tag_name }}"
HEADER_RELEASE="$(cat zend_scoutapm.h | grep "PHP_SCOUTAPM_VERSION" | awk '{print $3}' | tr -d '"')"
echo "Previous release: $PREVIOUS_RELEASE"
echo "PHP_SCOUTAPM_VERSION in header: $HEADER_RELEASE"
if [[ "$PREVIOUS_RELEASE" = "$HEADER_RELEASE" ]]
then
echo "PHP_SCOUTAPM_VERSION in zend_scoutapm.h has NOT been changed, cannot release"
exit 1
else
echo "Version in zend_scoutapm.h HAS been changed."
exit 0
fi
- name: "Extract latest version from package.xml"
uses: QwerMike/xpath-action@v1
id: get_package_xml_version
with:
filename: 'package.xml'
expression: "//*[local-name()='package']/*[local-name()='version']/*[local-name()='release']/text()"
- name: "Check package.xml version release has been changed"
run: |
PREVIOUS_RELEASE="${{ fromJson(steps.get_previous_release_step.outputs.data).tag_name }}"
XML_RELEASE="${{ steps.get_package_xml_version.outputs.result }}"
echo "Previous release: $PREVIOUS_RELEASE"
echo "package.xml version: $XML_RELEASE"
if [[ "$PREVIOUS_RELEASE" = "$XML_RELEASE" ]]
then
echo "package.xml version has NOT been changed, cannot release"
exit 1
else
echo "Version in package.xml HAS been changed."
exit 0
fi
release:
name: "Tag, release & create merge-up PR"
needs: [ "pre-verify-release" ]
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: "Release"
uses: "docker://ghcr.io/laminas/automatic-releases:1.13"
with:
args: "laminas:automatic-releases:release"
env:
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Fetch rate limit stats"
uses: octokit/request-action@v2.x
id: get_latest_release
with:
route: GET /rate_limit
env:
GITHUB_TOKEN: ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
- name: "Display rate limit stats"
run: echo "${{ steps.get_latest_release.outputs.data }}"
- name: "Create Merge-Up Pull Request"
uses: "docker://ghcr.io/laminas/automatic-releases:1.13"
with:
args: "laminas:automatic-releases:create-merge-up-pull-request"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create and/or Switch to new Release Branch"
uses: "docker://ghcr.io/laminas/automatic-releases:1.13"
with:
args: "laminas:automatic-releases:switch-default-branch-to-next-minor"
env:
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
- name: "Create new milestones"
uses: "docker://ghcr.io/laminas/automatic-releases:1.13"
with:
args: "laminas:automatic-releases:create-milestones"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
post-release-assets:
name: "Create assets post-release"
needs: [ "release_parameters", "release" ]
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.release_parameters.outputs.ref_for_version_to_tag }}
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
coverage: "none"
php-version: "8.0"
tools: pecl
- name: "Build PECL Package"
run: pecl package
- name: "Fetch new release from Github API"
uses: octokit/request-action@v2.x
id: get_new_release_step
with:
route: GET /repos/scoutapp/scout-apm-php-ext/releases/tags/${{ needs.release_parameters.outputs.version_to_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Upload PECL package to latest release"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ fromJson(steps.get_new_release_step.outputs.data).upload_url }}
asset_path: ./scoutapm-${{ fromJson(steps.get_new_release_step.outputs.data).tag_name }}.tgz
asset_name: scoutapm-${{ fromJson(steps.get_new_release_step.outputs.data).tag_name }}.tgz
asset_content_type: application/gzip
- uses: actions/download-artifact@v3
with:
name: DLL ${{ needs.release_parameters.outputs.version_to_tag }}
- name: "Upload Windows DLLs to latest release"
# sauce: https://github.com/actions/upload-release-asset/issues/28#issuecomment-675297045
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ls -l php_scoutapm-*.zip
RELEASE="${{ needs.release_parameters.outputs.version_to_tag }}"
ASSETS=$(find . -type f -name "php_scoutapm-*.zip" -printf "-a %p ")
echo "release = $RELEASE"
echo "assets = $ASSETS"
hub release edit $ASSETS -m "" "$RELEASE"