| 1 |
name: GitHub Release |
| 2 |
on: |
| 3 |
workflow_dispatch: |
| 4 |
inputs: |
| 5 |
version: |
| 6 |
description: "Version number to release" |
| 7 |
required: true |
| 8 |
|
| 9 |
concurrency: |
| 10 |
group: release-${{ github.ref }} |
| 11 |
cancel-in-progress: true |
| 12 |
|
| 13 |
# Deny all permissions at workflow level - scope per job |
| 14 |
permissions: {} |
| 15 |
|
| 16 |
env: |
| 17 |
GHP_BASE_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }} |
| 18 |
|
| 19 |
jobs: |
| 20 |
release: |
| 21 |
name: Create GitHub Release |
| 22 |
runs-on: ubuntu-latest |
| 23 |
permissions: |
| 24 |
contents: write # Required for creating releases and tags |
| 25 |
env: |
| 26 |
VERSION: ${{ github.event.inputs.version }} # zizmor: ignore[template-injection] -- User input is required for this workflow |
| 27 |
GHP_BASE_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }} |
| 28 |
GALAXY_API_KEY: ${{ secrets.GALAXY_API_KEY }} # zizmor: ignore[secrets-outside-env] -- Galaxy API key needed for publishing; workflow_dispatch only |
| 29 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # zizmor: ignore[secrets-outside-env] -- GitHub token needed for release creation; workflow_dispatch only |
| 30 |
steps: |
| 31 |
- name: Checkout |
| 32 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 33 |
with: |
| 34 |
persist-credentials: false |
| 35 |
|
| 36 |
- name: Set up Python |
| 37 |
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 38 |
with: |
| 39 |
python-version: 3.8 |
| 40 |
|
| 41 |
- name: Install PyYaml |
| 42 |
run: pip install pyyaml |
| 43 |
|
| 44 |
- name: Publish to Galaxy |
| 45 |
uses: artis3n/ansible_galaxy_collection@ffbca2460a5a1c600b941bbf1536bd61de1c2227 # v3.0.0 |
| 46 |
with: |
| 47 |
api_key: ${{ env.GALAXY_API_KEY }} |
| 48 |
|
| 49 |
- name: Validate version is published to Galaxy |
| 50 |
run: curl --head -s -f -o /dev/null "https://galaxy.ansible.com/download/lowlydba-sqlserver-${VERSION}.tar.gz" |
| 51 |
|
| 52 |
- name: Build release description |
| 53 |
shell: python |
| 54 |
env: |
| 55 |
VERSION: ${{ env.VERSION }} |
| 56 |
GHP_BASE_URL: ${{ env.GHP_BASE_URL }} |
| 57 |
run: | |
| 58 |
import os |
| 59 |
import yaml |
| 60 |
|
| 61 |
ver = os.environ['VERSION'] |
| 62 |
ver_anchor = str.replace(ver, '.', '-') |
| 63 |
|
| 64 |
with open('changelogs/changelog.yaml', 'r') as s: |
| 65 |
ri = yaml.safe_load(s) |
| 66 |
|
| 67 |
if ('release_summary' not in ri['releases'][ver]['changes']): |
| 68 |
summary = 'No release summary available.' |
| 69 |
else: |
| 70 |
summary = ri['releases'][ver]['changes']['release_summary'] |
| 71 |
|
| 72 |
reldate = ri['releases'][ver]['release_date'] |
| 73 |
|
| 74 |
description = '''## Summary |
| 75 |
Released: %s |
| 76 |
|
| 77 |
%s |
| 78 |
|
| 79 |
--- |
| 80 |
|
| 81 |
View the [complete changelog](https://github.com/lowlydba/lowlydba.sqlserver/blob/main/CHANGELOG.rst#v%s) to see all changes. |
| 82 |
|
| 83 |
View the [full documentation for release %s](%s/tag/%s). |
| 84 |
''' % (reldate, summary, ver_anchor, ver, os.environ['GHP_BASE_URL'], ver) |
| 85 |
|
| 86 |
with open(os.environ['GITHUB_ENV'], 'a') as e: |
| 87 |
e.write("RELEASE_DESCRIPTION<<EOF\n%s\nEOF" % description) |
| 88 |
|
| 89 |
- name: Create Release |
| 90 |
id: create_release |
| 91 |
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # zizmor: ignore[superfluous-actions] -- Using action for release creation provides better GitHub API integration and version tagging features |
| 92 |
with: |
| 93 |
token: ${{ env.GITHUB_TOKEN }} |
| 94 |
tag_name: ${{ env.VERSION }} |
| 95 |
name: ${{ env.VERSION }} |
| 96 |
body: ${{ env.RELEASE_DESCRIPTION }} |