Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate changelog including cli refactor #7

Merged
merged 67 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
37412ee
Refactor cli calls
philnewm Sep 16, 2024
19044f6
Move logic into dedicated files
philnewm Sep 17, 2024
172207b
Fix typo
philnewm Sep 17, 2024
c06979a
Add major bump
philnewm Sep 30, 2024
5e45bb5
Add raise in terms of wrong datatype
philnewm Sep 30, 2024
b9766f7
Implement basic changelog filtering
philnewm Oct 15, 2024
0ce18b7
Implement markdown change output
philnewm Oct 17, 2024
5257cf3
Small refactor
philnewm Oct 18, 2024
d5cfd4e
Refactor cli call to use click
philnewm Oct 19, 2024
48f05b0
Update workflow for expected failure
philnewm Oct 19, 2024
ef02f45
Enable changelog display again
philnewm Oct 19, 2024
0196c6e
Update branch pointer
philnewm Oct 19, 2024
86f3f03
Replace return with click.echo
philnewm Oct 19, 2024
d96fe3b
Disable all non-relevant steps
philnewm Oct 19, 2024
f07524e
Implement multiline processing according to docs
philnewm Oct 19, 2024
3c66f44
Fix typo
philnewm Oct 19, 2024
66f69ef
Add generic delimiter
philnewm Oct 19, 2024
5a2fa98
Try different method
philnewm Oct 19, 2024
1bf4174
Add info comment
philnewm Oct 19, 2024
49ac1c0
Add cli formatting
philnewm Oct 19, 2024
4f5bcbe
Debug multiline string display
philnewm Oct 19, 2024
a37a78e
Move string formatting to ci workflow
philnewm Oct 19, 2024
f11eb9a
Reenable other inputs and outputs
philnewm Oct 21, 2024
b035753
Add argparse import back in
philnewm Oct 21, 2024
4a73d84
Update ci workflow
philnewm Oct 21, 2024
24152b0
Remove unnecessary debug code
philnewm Oct 21, 2024
63d4832
Adjust formatting for GITHUB_OUTPUT
philnewm Oct 22, 2024
39e0a8d
Extend debug output formatting
philnewm Oct 22, 2024
b4dd09d
Further formatting updates
philnewm Oct 22, 2024
80f13da
Update formatting
philnewm Oct 22, 2024
f62e603
Update formatting
philnewm Oct 22, 2024
0390cfb
Update formatting
philnewm Oct 22, 2024
ff788cb
Add first changelog test
philnewm Oct 24, 2024
1c90ee2
Integrate changelog creation into action.yml
philnewm Oct 25, 2024
66dfab5
Update variable reference
philnewm Oct 28, 2024
a970cdc
Fix typo in variable reference
philnewm Oct 28, 2024
e788396
Update ci-action
philnewm Oct 28, 2024
9f9efc0
FIx bracket typo
philnewm Oct 28, 2024
e8020ba
Fix query label splitting
philnewm Oct 28, 2024
e3da661
Add variable $ sign for evaluation
philnewm Oct 28, 2024
3dba933
remove variable query
philnewm Oct 28, 2024
4fc7fd7
Add query labels
philnewm Oct 28, 2024
b4f09af
Add debug output for changelog issues
philnewm Oct 28, 2024
1107e74
Update variable reference
philnewm Oct 29, 2024
29104c1
Remove obsolete debug output
philnewm Oct 29, 2024
bba78ae
Add label filtering before output
philnewm Oct 29, 2024
862b5e0
Update script docstring
philnewm Oct 29, 2024
4479a62
Update structure to match refactor branch
philnewm Oct 29, 2024
c06e147
Fix list conversion
philnewm Oct 29, 2024
cdf6aed
Update labels function call
philnewm Oct 29, 2024
19e3f1c
Update bump-increment step to click version
philnewm Oct 30, 2024
6a1048f
Include csv conversion for version increment calls
philnewm Oct 30, 2024
014bb78
Merge branch 'refactor-cli-calls' into generate-changelog
philnewm Oct 30, 2024
720f072
Remove duplicate test
philnewm Oct 30, 2024
2a362ef
Cleanup changelog creation
philnewm Nov 4, 2024
2668e98
Remove obsolete function
philnewm Nov 4, 2024
1e393fa
Update caller functions
philnewm Nov 4, 2024
e73ef72
Add missing return statement
philnewm Nov 4, 2024
165e754
Enhance changelog creation
philnewm Nov 4, 2024
6c9ad3a
Add details formatting to changelog
philnewm Nov 4, 2024
7ede1a9
Add details to changelog
philnewm Nov 5, 2024
e53155b
Update function name
philnewm Nov 5, 2024
3dde7bb
Update url handling in changelog
philnewm Nov 5, 2024
031eb3e
Add unit-test for changelog description formatting
philnewm Nov 5, 2024
1154f26
Move json fixtures to files
philnewm Nov 5, 2024
2185536
Add documentation to readme
philnewm Nov 5, 2024
7ddf77b
Add testing information to readme
philnewm Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/action-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,22 @@ jobs:
steps:
- name: Run action
id: test-action
uses: ynput/github-query@main
uses: ynput/github-query@generate-changelog
with:
repo: "ynput/ayon-addon-action-testing"
date: "2024-08-20T12:03:23Z"
query_parameters: "body,labels,title"
query_parameters: "body,labels,title,number,url,id"
changelog_labels: "feature,enhancement,bugfix,refactor,docs,test,pr"

- name: Show results
run: |
echo "RAW-response: " && echo '${{ steps.test-action.outputs.raw-output }}'
echo "Labels: " && echo '${{ steps.test-action.outputs.label-list }}'
echo "Bump-increment: " && echo '${{ steps.test-action.outputs.bump-increment }}'
# echo "Changelog: " && echo '${{ steps.test-action.outputs.changelog-markdown }}'
echo "Changelog: " && echo '${{ steps.test-action.outputs.changelog-markdown }}'


- name: Show changelog formatted
shell: bash
run: |
printf '${{ steps.test-action.outputs.changelog-markdown }}'
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
# CI-Status
# Github-Query

[![CI-Status](https://github.com/ynput/github-query/actions/workflows/action-ci.yml/badge.svg)](https://github.com/ynput/github-query/actions/workflows/action-ci.yml)

# Github-Data
Fetch and convert certain information retrieved from github
**This is a customized query action for Ayon-related repo-workflows.**

## Purpose

This action mainly queries pull request related information.
It got a bunch of conversion going on to prepare the data for further usage. This includes

* Filtering PR labels
* Suggest version increment based on found labels
* Preparing data structure for release information
* Prepare a markdown formatted changelog based on PR information

## Usage

For details see [action.yml](https://github.com/ynput/github-query/blob/main/action.yml) file

```yaml
- name: Query PR data
uses: ynput/github-query@main
with:
# Repository name with owner. For example, actions/checkout
repo: ""
# Date-Time-Stamp as a starting point for the query, will only process merged PRs newer then that date
# format: "2024-08-20T12:03:23Z"
date: ""
# JSON keys to query for in a gh query command
# gh pr list --state merged --search f'merged:>=<date>' --json "body,labels,title,id,number,url" --repo <repo_name>
query_parameters: ""
# Define change log content and order by this comma separated value string
# example: "enhancement,bugfix,docs"
changelog_labels: ""
```

## Outputs

* raw-output - Full output json dictionary from github api
* label-list - List of unique labels found in PRs
* bump-increment - Increment for version bumping - either 'patch', 'minor' or 'major'
* changelog-markdown - String containing markdown formatted release changelog

## Testing

Unit-test are included in `tests/` and will run on every pr targeting main and very push to main.
These tests can be run local by changing into the `tests/` directory and running `pytest`

## Developer-Hints

The python file `github_query.py` calls all the main logic and provides it's function to `action.yml` through click-parameters.
This makes the python function calls convenient to use from terminal while keeping them easy to test.
16 changes: 0 additions & 16 deletions TODO.md

This file was deleted.

51 changes: 29 additions & 22 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---

# TODO need strategy where to store defaults - which an be overriden by repo var
# TODO need strategy where to store defaults - which an be override by repo var

name: Github Release Information
description: Fetch and convert data from github to use for a release trigger

branding:
icon: plus
icon: arrow-left-circle
color: green

inputs:
Expand All @@ -19,6 +19,9 @@ inputs:
query_parameters:
description: Parameters to query for in pr Information
required: true
changelog_labels:
description: CSV string of labels for changelog order
required: false

outputs:
raw-output:
Expand All @@ -30,9 +33,9 @@ outputs:
bump-increment:
description: Increment for version bumping - either `patch` or 'minor'
value: ${{ steps.bump-increment.outputs.increment }}
# changelog-markdown:
# description: String containing full makrdown syntax for release changelog information
# value: ${{ steps.write-changelog.outputs.changelog }}
changelog-markdown:
description: String containing full markdown syntax for release changelog information
value: ${{ steps.write-changelog.outputs.changelog }}

runs:
using: composite
Expand All @@ -55,31 +58,35 @@ runs:
shell: bash
run: |
cd $GITHUB_ACTION_PATH
label_list=$(python -c 'import github_query; print(github_query.get_labels(github_query.parse_args()))' "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}")
if [[ "$label_list" == '[]' ]]; then
echo "label_list=''" >> $GITHUB_OUTPUT
exit 0
fi

label_list=$(python github_query.py pr-labels "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}")

echo "label_list=$label_list" >> $GITHUB_OUTPUT

- name: Get version increment
id: bump-increment
shell: bash
run: |
cd $GITHUB_ACTION_PATH
increment=$(python -c 'import github_query; pr_labels = github_query.get_labels(github_query.parse_args()); patch_repo_var = github_query.get_repo_var(repo="${{ inputs.repo }}", var_name="PATCH_BUMP_LABEL"); minor_repo_var = github_query.get_repo_var(repo="${{ inputs.repo }}", var_name="MINOR_BUMP_LABEL"); print(github_query.get_version_increment(patch_bump_list=patch_repo_var, minor_bump_list=minor_repo_var, pr_label_list=pr_labels))' "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}")
increment=$(python github_query.py version-increment "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}")

echo "increment=$increment" >> $GITHUB_OUTPUT

# disabled until fixed
# - name: Prepare Changelog
# id: write-changelog
# shell: bash
# run: |
# cd $GITHUB_ACTION_PATH
# changelog=$(python -c 'import github_query; gh_query = github_query.parse_args(); patch_repo_var = github_query.get_repo_var(repo="${{ inputs.repo }}", var_name="PATCH_BUMP_LABEL"); minor_repo_var = github_query.get_repo_var(repo="${{ inputs.repo }}", var_name="MINOR_BUMP_LABEL"); print(github_query.prepare_changelog_markdown(pr_query=gh_query, minor_bump_list=minor_repo_var, patch_bump_list=patch_repo_var))' "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}")
# oneline_changelog=$(echo "$changelog" | base64 | tr -d '/n')
# echo "oneline changelog: $oneline_changelog"
# # echo "changelog=$oneline_changelog" >> $GITHUB_OUTPUT
# INFO multiline strings need to be precessed like this according to
# INFO https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#multiline-strings
# INFO and
# INFO https://stackoverflow.com/questions/74137120/how-to-fix-or-avoid-error-unable-to-process-file-command-output-successfully/74232400#74232400
- name: Prepare Changelog
if: ${{ inputs.changelog_labels }}
id: write-changelog
shell: bash
run: |
cd $GITHUB_ACTION_PATH
changelog=$(python github_query.py generate-release-changelog "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}" "${{ inputs.changelog_labels }}")
delimiter="$(openssl rand -hex 8)"
{
echo "changelog<<${delimiter}"
echo "$changelog"
echo "${delimiter}"
} >> $GITHUB_OUTPUT

...
Loading