ODS-tools Release #37
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ODS-tools Release | |
on: | |
workflow_dispatch: | |
inputs: | |
release_tag: | |
description: 'Release tag to publish as [semvar]' | |
required: true | |
prev_release_tag: | |
description: 'The previous release version [semvar]' | |
required: true | |
pre_release: | |
description: 'Mark GitHub release as pre-release: [true, false]' | |
required: true | |
default: 'false' | |
env: | |
RELEASE_TAG: ${{ inputs.release_tag }} | |
PREV_RELEASE_TAG: ${{ inputs.prev_release_tag }} | |
PRE_RELEASE: ${{ inputs.pre_release }} | |
jobs: | |
update: | |
uses: ./.github/workflows/version.yml | |
secrets: inherit | |
with: | |
package_version: ${{ inputs.release_tag }} | |
package: | |
uses: ./.github/workflows/build.yml | |
secrets: inherit | |
needs: update | |
release: | |
runs-on: ubuntu-latest | |
needs: package | |
outputs: | |
heading: ${{ steps.slack_vars.outputs.heading }} | |
title: ${{ steps.slack_vars.outputs.title }} | |
build_branch: ${{ steps.slack_vars.outputs.branch }} | |
run_url: ${{ steps.slack_vars.outputs.run_url }} | |
run_id: ${{ steps.slack_vars.outputs.run_id }} | |
run_status: ${{ steps.slack_vars.outputs.run_status }} | |
run_date: ${{ steps.slack_vars.outputs.run_date }} | |
steps: | |
- name: is branch valid for release | |
if: ${{ !startsWith(github.ref_name , 'release/') }} | |
run: | | |
echo "Releases must be trigged on branch named 'release/x.x.x'" | |
exit 1 | |
- name: Check tag is valid for release | |
if: env.PRE_RELEASE == 'false' | |
run: | | |
VALID=$(echo ${{ env.RELEASE_TAG }} | grep -oPc "^(\d+)\.(\d+)\.(\d+)$") | |
if [[ ! "$VALID" == 1 ]]; then | |
echo "Release Tag ${{ env.RELEASE_TAG }} is not valid" | |
exit 1 | |
fi | |
- name: Check tag is valid for pre-release | |
if: env.PRE_RELEASE == 'true' | |
run: | | |
VALID=$(echo ${{ env.RELEASE_TAG }} | grep -oPc "^(\d+)\.(\d+)\.(\d+)rc(\d+)$") | |
if [[ ! "$VALID" == 1 ]]; then | |
echo "Release Tag ${{ env.RELEASE_TAG }} is not valid" | |
exit 1 | |
fi | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref_name }} | |
fetch-depth: 0 | |
- name: Check tag matches version set | |
run: | | |
BUILD_VER=$(grep '__version__' ods_tools/__init__.py | awk -F"'" '{print $2}') | |
RELEASE_VER=${{ env.RELEASE_TAG }} | |
[[ "$RELEASE_VER" = "$BUILD_VER" ]] && ERROR_CODE=0 || ERROR_CODE=1 | |
if [[ "$ERROR_CODE" == 1 ]]; then | |
echo "PACKAGE_VER: $BUILD_VER stored in 'ods_tools/__init__.py' dosn't match RELEASE_TAG: $RELEASE_VER" && exit $ERROR_CODE | |
fi | |
- name: Test package names | |
run: | | |
ERROR_CODE=0 | |
SRC_VER=$(echo ${{ needs.package.outputs.src_filename }} | grep -oP "(\d+)\.(\d+)\.(\d+)rc(\d+)|(\d+)\.(\d+)\.(\d+)") | |
BIN_VER=$(echo ${{ needs.package.outputs.whl_filename }} | grep -oP "(\d+)\.(\d+)\.(\d+)rc(\d+)|(\d+)\.(\d+)\.(\d+)") | |
[[ "${{ env.RELEASE_TAG }}" = "$SRC_VER" ]] || ERROR_CODE=1 | |
[[ "${{ env.RELEASE_TAG }}" = "$BIN_VER" ]] || ERROR_CODE=1 | |
if [[ "$ERROR_CODE" == 1 ]]; then | |
echo "Package names don't match release tag." | |
echo " RELEASE_TAG: ${{ env.RELEASE_TAG }}" | |
echo " PACKAGES: ${{ needs.package.outputs.src_filename }}, ${{ needs.package.outputs.whl_filename }}" | |
exit $ERROR_CODE | |
fi | |
- name: Setup github user | |
run: | | |
git config --global user.email ${{ env.GIT_EMAIL }} | |
git config --global user.name ${{ env.GIT_USERNAME }} | |
git config --global pull.ff only | |
env: | |
GIT_EMAIL: ${{ secrets.BUILD_GIT_EMAIL }} | |
GIT_USERNAME: ${{ secrets.BUILD_GIT_USERNAME }} | |
- name: Tag Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }} | |
run: | | |
git checkout ${{ github.ref_name }} | |
git tag ${{ env.RELEASE_TAG }} | |
# --- Create Changelog --- # | |
- name: Setup python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Setup Changelog builder | |
run: | | |
BRANCH='main' | |
BASE_URL="https://raw.githubusercontent.com/OasisLMF/OasisPlatform/$BRANCH/scripts" | |
pip install -r $BASE_URL/requirments-changelog.txt | |
wget $BASE_URL/update-changelog.py | |
chmod +x update-changelog.py | |
- name: Create changelog | |
env: | |
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }} | |
run: | | |
${{ github.workspace }}/update-changelog.py build-changelog \ | |
--repo ${{ github.event.repository.name }} \ | |
--from-tag ${{ env.PREV_RELEASE_TAG }} \ | |
--to-tag ${{ env.RELEASE_TAG }} \ | |
--github-token ${{ secrets.BUILD_GIT_TOKEN }} \ | |
--local-repo-path ./ \ | |
--output-path ./CHANGELOG.rst \ | |
--apply-milestone | |
git add ./CHANGELOG.rst | |
git commit -m 'Update changelog' | |
- name: Create Release notes | |
working-directory: ${{ env.WORKSPACE }} | |
run: | | |
${{ github.workspace }}/update-changelog.py build-release \ | |
--repo ${{ github.event.repository.name }} \ | |
--from-tag ${{ env.PREV_RELEASE_TAG }} \ | |
--to-tag ${{ env.RELEASE_TAG }} \ | |
--github-token ${{ secrets.BUILD_GIT_TOKEN }} \ | |
--local-repo-path ./ \ | |
--output-path ./RELEASE.md | |
# --- Sign packages --- # | |
- name: Download Source package | |
uses: actions/download-artifact@v4 | |
with: | |
name: src_package | |
path: ${{ github.workspace }}/ | |
- name: Download Linux package | |
uses: actions/download-artifact@v4 | |
with: | |
name: bin_package | |
path: ${{ github.workspace }}/ | |
# --- Create Release --- # | |
- name: Push changes | |
run: | | |
git push origin ${{ env.RELEASE_TAG }} | |
git push | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }} | |
with: | |
tag_name: ${{ env.RELEASE_TAG }} | |
release_name: Release ${{ env.RELEASE_TAG }} | |
body_path: ${{ github.workspace }}/RELEASE.md | |
draft: false | |
prerelease: ${{ env.PRE_RELEASE }} | |
# --- Attach build assest --- # | |
- name: Upload Source package | |
id: upload-source-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ github.workspace }}/${{ needs.package.outputs.src_filename }} | |
asset_name: ${{ needs.package.outputs.src_filename }} | |
asset_content_type: application/octet-stream | |
- name: Upload Wheel package | |
id: upload-linux-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.BUILD_GIT_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ github.workspace }}/${{ needs.package.outputs.whl_filename }} | |
asset_name: ${{ needs.package.outputs.whl_filename }} | |
asset_content_type: application/octet-stream | |
# --- Publish to Pypi --- # | |
- name: Setup Twine | |
run: pip install twine | |
- name: PYPI - Source package | |
run: twine upload ${{ needs.package.outputs.src_filename }} | |
env: | |
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | |
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | |
- name: PYPI - Linux package | |
run: twine upload ${{ needs.package.outputs.whl_filename }} | |
env: | |
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | |
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | |
# --- Slack notify --- # | |
- name: slack message vars | |
id: slack_vars | |
run: | | |
HEAD=$(echo "*${{ github.event.repository.name}} Release* (${{ env.RELEASE_TAG }})") | |
DATE=$(date) | |
TITLE=$(echo "• <https://github.com/${{ github.repository }}/releases/tag/${{ env.RELEASE_TAG }}|${{ github.event.repository.name }} ${{ env.RELEASE_TAG }} - Release Notes>") | |
JOB_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
echo "heading=$HEAD" >> $GITHUB_OUTPUT | |
echo "run_date=$DATE" >> $GITHUB_OUTPUT | |
echo "title=$TITLE" >> $GITHUB_OUTPUT | |
echo "run_url=$JOB_URL" >> $GITHUB_OUTPUT | |
echo "run_id=${{ github.run_id }}" >> $GITHUB_OUTPUT | |
echo "branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
echo "run_status=${{ job.status }}" >> $GITHUB_OUTPUT | |
slack: | |
uses: OasisLMF/OasisLMF/.github/workflows/notify.yml@main | |
secrets: inherit | |
needs: release | |
with: | |
heading: ${{ needs.release.outputs.heading }} | |
title: ${{ needs.release.outputs.title }} | |
build_branch: ${{ needs.release.outputs.build_branch }} | |
run_url: ${{ needs.release.outputs.run_url }} | |
run_id: ${{ needs.release.outputs.run_id }} | |
run_status: ${{ needs.release.outputs.run_status }} | |
run_date: ${{ needs.release.outputs.run_date }} |