feat: add ci workflow for auto generating changelog

Signed-off-by: gardar <gardar@users.noreply.github.com>
This commit is contained in:
gardar 2023-02-17 18:51:36 +00:00
parent 36966a1528
commit 918e7863fd
No known key found for this signature in database
GPG key ID: 75FAE37CBA8C13C2
5 changed files with 140 additions and 92 deletions

52
.github/release-drafter.yml vendored Normal file
View file

@ -0,0 +1,52 @@
name-template: '$RESOLVED_VERSION'
tag-template: '$RESOLVED_VERSION'
categories:
- title: 'Major Changes'
labels:
- 'major' # c6476b
- title: 'Minor Changes'
labels:
- 'feature' # 006b75
- 'enhancement' # ededed
- 'refactoring'
- title: 'Bugfixes'
labels:
- 'bug' # fbca04
- title: 'Deprecations'
labels:
- 'deprecated' # fef2c0
exclude-labels:
- 'skip-changelog'
- 'duplicate'
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
- 'feature'
- 'enhancement'
- 'refactoring'
patch:
labels:
- 'patch'
- 'bug'
- 'deprecated'
default: patch
autolabeler:
- label: 'skip-changelog'
title: '/chore/i'
- label: 'bug'
title: '/fix/i'
- label: 'enhancement'
title: '/(enhance|improve)/i'
- label: 'feature'
title: '/feature/i'
- label: 'dreprecated'
title: '/deprecat/i'
change-template: '* $TITLE by @$AUTHOR in #$NUMBER'
template: |
What's Changed
===
$CHANGES

4
.github/version-drafter.yml vendored Normal file
View file

@ -0,0 +1,4 @@
---
major-labels: ['semver:major', 'major', 'breaking']
minor-labels: ['semver:minor', 'minor', 'enhancement', 'deprecated', 'removed', 'security']
patch-labels: ['semver:patch', 'bug', 'trivial', 'bugfix']

View file

@ -1,89 +0,0 @@
name: Publish Collection
on:
push:
branches:
- main
release:
types:
- 'published'
env:
python-version: 3.9
jobs:
publish-latest:
if: github.event_name == 'push'
runs-on: ubuntu-22.04
defaults:
run:
working-directory: ansible_collections/prometheus/prometheus
steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: ansible_collections/prometheus/prometheus
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: ${{ env.python-version }}
- name: Install ansible-base (devel)
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
- name: Build the collection
run: ansible-galaxy collection build
- name: Rename the build artifact
run: mv prometheus-prometheus-*.tar.gz prometheus-community-prometheus-latest.tar.gz
# Moving the tag leaves an orphan artifact. Just changing the artifact doesn't move the tag.
- name: Delete latest tag and release
uses: dev-drprasad/delete-tag-and-release@v0.1.2
with:
delete_release: true
tag_name: latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload files to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ansible_collections/prometheus/prometheus/prometheus-community-prometheus-latest.tar.gz
asset_name: prometheus-community-prometheus-latest.tar.gz
body: "Development release"
tag: latest
overwrite: true
publish-tagged:
if: github.event_name == 'release'
runs-on: ubuntu-22.04
defaults:
run:
working-directory: ansible_collections/prometheus/prometheus
steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: ansible_collections/prometheus/prometheus
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: ${{ env.python-version }}
- name: Install ansible-base (devel)
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
- name: Build the collection
run: ansible-galaxy collection build
- name: Upload files to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ansible_collections/prometheus/prometheus/prometheus-community-prometheus-*.tar.gz
file_glob: true
tag: ${{ github.ref }}
overwrite: true

81
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,81 @@
---
name: Ansible collection release
on:
pull_request:
types:
- closed
jobs:
release:
if: |
github.event.pull_request.merged &&
github.ref == github.event.repository.default_branch &&
!contains(github.event.pull_request.labels.*.name, 'skip-release')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: "Install tools"
run: "python -m pip install ansible-base antsibull-changelog --disable-pip-version-check"
- name: "Calculate next version"
id: version
uses: gardar/version-drafter-action@event-triggers # Until PR gets merged: https://github.com/patrickjahns/version-drafter-action/pull/343
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: "Check git repo before changelog"
run: git status
- name: "Generate new version in changelog.yaml"
run: antsibull-changelog release -v --version "${{ steps.version.outputs.next-version }}"
- name: "Run antsichaut"
uses: gardar/antsichaut-action@yaml-lint # Until PR gets merged: https://github.com/rndmh3ro/antsichaut/pull/4
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
since_version: "${{ steps.version.outputs.current-version }}"
- name: "Update Changelog.rst"
run: "antsibull-changelog generate -v"
- name: "Update collection version"
uses: mikefarah/yq@master
with:
cmd: yq -i '.version = "${{ steps.version.outputs.next-version }}"' 'galaxy.yml'
- name: "Check git repo"
run: git status
- name: "Write changelog and version"
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: ${{ github.event.pull_request.base.ref }}
commit_message: "chore: update version"
- name: "Checkout updated branch"
uses: actions/checkout@v3.3.0
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: "Build the collection"
run: ansible-galaxy collection build
- name: "Publish release"
id: release-publish
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
publish: true
- name: "Upload built collection to release"
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: prometheus-prometheus-*.tar.gz
file_glob: true
tag: ${{ steps.release-publish.outputs.tag_name }}
overwrite: true

View file

@ -42,9 +42,9 @@ to a commit with merge request. Available keywords are (square brackets are impo
* `[major]`, `[breaking change]` - for MAJOR version release
## Changelog
Changelog is generated automatically during release process and all information is taken from github issues, PRs and
labels.
This project uses [antsibull-changelog](https://docs.ansible.com/ansible/latest/dev_guide/developing_collections_changelogs.html#generating-changelogs) to generate changelogs.
Changelog is generated automatically during release process and all information is taken from github PRs, commits and labels.
## Expectations