-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GitHub Actions workflows for test,publish,notify, Adjusted vers…
…ions Details: * Added the test,publish,notify workflows * Adjusted some dependent package versions. * Increased zhmcclient to 1.16.1 to get correct stomp-py package name. * Increased jsonschema to 3.1.0 to match the new minimum of zhmcclient. Signed-off-by: Andreas Maier <[email protected]>
- Loading branch information
1 parent
1561a3f
commit 81b796f
Showing
9 changed files
with
482 additions
and
43 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This GitHub workflow will send a notification to Slack when a scheduled test | ||
# workflow completes. | ||
|
||
# There needs to be a GitHub secret named "SLACK_HOOK" that is set to the | ||
# incoming webhook URL for Slack. That webhook is tied to a Slack channel, so | ||
# this workflow does not select the channel and relies on that default. | ||
# Instructions to set up Slack for incoming webhooks are here: | ||
# https://api.slack.com/messaging/webhooks. | ||
|
||
name: notify | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- test | ||
types: | ||
- completed | ||
|
||
jobs: | ||
|
||
notify: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.event == 'schedule' }} | ||
steps: | ||
|
||
- name: Post status to Slack | ||
run: | | ||
run_id=$(echo "${{ github.event.workflow_run.url }}" | rev | cut -d '/' -f 1 | rev) | ||
run_url="https://github.com/${{ github.repository }}/actions/runs/$run_id" | ||
branch="${{ github.event.workflow_run.head_branch }}" | ||
branch_url="https://github.com/${{ github.repository }}/commits/$branch" | ||
repo_url="https://github.com/${{ github.repository }}/actions/workflows/test.yml" | ||
emoji=$(if [[ "${{ github.event.workflow_run.conclusion }}" == "success" ]]; then echo ":white_check_mark:"; else echo ":x:"; fi) | ||
json="{ \"text\": \"$emoji <$repo_url|${{ github.repository }}>: Scheduled run <$run_url|$run_id> on branch <$branch_url|$branch>: ${{ github.event.workflow_run.conclusion }}\" }" | ||
curl -s -d "payload=$json" ${{ secrets.SLACK_HOOK }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
# This GitHub workflow will publish the package to Pypi and create a new stable branch when releasing the master branch. | ||
# For more information see: | ||
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ | ||
|
||
name: publish | ||
|
||
on: | ||
push: # When pushing a tag | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
publish: | ||
name: Build and publish to PyPI | ||
if: startsWith(github.ref, 'refs/tags') | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
#-------- Info gathering and checks | ||
- name: Set pushed tag | ||
id: set-tag | ||
uses: actions/github-script@v7 | ||
with: | ||
result-encoding: string | ||
script: | | ||
const result = "${{ github.ref }}".match("refs/tags/(.*)$")[1] | ||
console.log(result) | ||
return result | ||
- name: Check validity of pushed tag | ||
run: | | ||
if [[ ${{ steps.set-tag.outputs.result }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo "Pushed tag '${{ steps.set-tag.outputs.result }}' is valid"; | ||
else | ||
echo "Pushed tag '${{ steps.set-tag.outputs.result }}' is invalid (must be 'M.N.U')"; | ||
false; | ||
fi | ||
- name: Determine whether releasing the master branch | ||
id: set-is-master-branch | ||
uses: actions/github-script@v7 | ||
with: | ||
result-encoding: string | ||
script: | | ||
const resp = await github.rest.git.getRef({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
ref: "heads/master", | ||
}) | ||
const result = (resp.data.object.sha == "${{ github.sha }}") | ||
console.log(result) | ||
return result | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Determine name of stable branch for pushed tag | ||
id: set-stable-branch | ||
uses: actions/github-script@v7 | ||
with: | ||
result-encoding: string | ||
script: | | ||
const result = "stable_"+"${{ steps.set-tag.outputs.result }}".match("([0-9]+\.[0-9]+)\.")[1] | ||
console.log(result) | ||
return result | ||
- name: Determine whether releasing stable branch for pushed tag | ||
id: set-is-stable-branch | ||
uses: actions/github-script@v7 | ||
with: | ||
result-encoding: string | ||
script: | | ||
var resp | ||
try { | ||
resp = await github.rest.git.getRef({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
ref: "heads/${{ steps.set-stable-branch.outputs.result }}", | ||
}) | ||
} | ||
catch(err) { | ||
console.log("false (stable branch does not exist: "+err+")") | ||
return false | ||
} | ||
const result = (resp.data.object.sha == "${{ github.sha }}") | ||
console.log(result) | ||
return result | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Check released commit to be master branch or stable branch for pushed tag | ||
run: | | ||
if [[ ${{ steps.set-is-master-branch.outputs.result }} == 'false' && ${{ steps.set-is-stable-branch.outputs.result }} == 'false' ]]; then | ||
echo "Released commit is not 'master' or '${{ steps.set-stable-branch.outputs.result }}' branch"; | ||
false; | ||
fi | ||
- name: Set update version | ||
id: set-update-version | ||
uses: actions/github-script@v7 | ||
with: | ||
result-encoding: string | ||
script: | | ||
const result = "${{ steps.set-tag.outputs.result }}".match("[0-9]+\.[0-9]+\.([0-9]+)")[1] | ||
console.log(result) | ||
return result | ||
- name: Check update version to be 0 when releasing master branch | ||
if: ${{ steps.set-is-master-branch.outputs.result == 'true' }} | ||
run: | | ||
if [[ ${{ steps.set-update-version.outputs.result }} != '0' ]]; then | ||
echo "Update version '${{ steps.set-update-version.outputs.result }}' in tag '${{ steps.set-tag.outputs.result }}' is invalid (must be 0 when releasing master branch)"; | ||
false; | ||
fi | ||
- name: Check update version to be non-0 when releasing stable branch for pushed tag | ||
if: ${{ steps.set-is-stable-branch.outputs.result == 'true' }} | ||
run: | | ||
if [[ ${{ steps.set-update-version.outputs.result }} == '0' ]]; then | ||
echo "Update version '${{ steps.set-update-version.outputs.result }}' in tag '${{ steps.set-tag.outputs.result }}' is invalid (must be non-0 when releasing stable branch for pushed tag)"; | ||
false; | ||
fi | ||
#-------- Setup of work environment | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
- name: Development setup | ||
run: | | ||
make develop | ||
#-------- Publishing of package | ||
- name: Build the distribution | ||
run: | | ||
make build | ||
- name: Display the distribution directory | ||
run: | | ||
ls -l dist | ||
# - name: Publish distribution to TestPyPI | ||
# uses: pypa/gh-action-pypi-publish@release/v1 | ||
# with: | ||
# packages_dir: dist | ||
# password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
# repository_url: https://test.pypi.org/legacy/ | ||
- name: Publish distribution to PyPI | ||
if: startsWith(github.ref, 'refs/tags') | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
packages_dir: dist | ||
password: ${{ secrets.PYPI_API_TOKEN }} | ||
|
||
#-------- Creation of Github release | ||
- name: Determine whether release on Github exists for the pushed tag | ||
id: set-release-exists | ||
uses: octokit/[email protected] | ||
with: | ||
route: GET /repos/${{ github.repository }}/releases/tags/${{ steps.set-tag.outputs.result }} | ||
continue-on-error: true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Create release on Github for the pushed tag if it does not exist | ||
if: ${{ steps.set-release-exists.outputs.status == 404 }} | ||
uses: octokit/[email protected] | ||
with: | ||
route: POST /repos/${{ github.repository }}/releases | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
INPUT_TAG_NAME: ${{ steps.set-tag.outputs.result }} | ||
INPUT_NAME: "Release ${{ steps.set-tag.outputs.result }}" | ||
INPUT_BODY: "Change log https://zhmc-log-forwarder.readthedocs.io/en/${{ steps.set-tag.outputs.result }}/changes.html" | ||
|
||
#-------- Creation of stable branch | ||
# Note: This requires that in the branch protection rules for stable_*, | ||
# the "Restrict pushes that create matching branches" checkmark is | ||
# not set. | ||
- name: Create new stable branch when releasing master branch | ||
if: steps.set-is-master-branch.outputs.result == 'true' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
github.rest.git.createRef({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
ref: "refs/heads/${{ steps.set-stable-branch.outputs.result }}", | ||
sha: "${{ github.sha }}", | ||
}) | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Oops, something went wrong.