Skip to content

Commit

Permalink
fix: default config environment var (#3)
Browse files Browse the repository at this point in the history
* update shell env and rename default cfg, update workflow/readme
* use absolute container path for default config file
* usr: tweak default config for more data/ better output

Signed-off-by: Stephen L Arnold <[email protected]>
  • Loading branch information
sarnold authored Feb 27, 2021
1 parent 2ea09c7 commit 9319f68
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ jobs:

- name: Display changes file
run: cat CHANGES.md

- name: Checkout test repo
uses: actions/checkout@v2
with:
repository: sarnold/gitchangelog
path: gcl-test
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN apk --no-cache add \

RUN pip3 install https://github.com/sarnold/gitchangelog/archive/3.0.5.tar.gz

ADD ./.gitchangelog-release.rc /.gitchangelog-release.rc
ADD ./gitchangelog-release.rc /gitchangelog-release.rc

ADD ./genchangelog.sh /genchangelog.sh

Expand Down
39 changes: 32 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ By default this action will ues the ``gitchangelog.rc.github.release``
config file installed by the gitchangelog package.


.. _reStructuredText: https://docutils.sourceforge.io/rst.html
.. _MarkDown: https://www.markdownguide.org/


Usage
=====
Expand Down Expand Up @@ -58,29 +61,51 @@ Default configuration
github_token: ${{ secrets.GITHUB_TOKEN}}


Advanced configuration
----------------------
Full configuration
------------------

::

name: gitchangelog
on: [push]
on:
push:
# trigger a release on any tag push
tags:
- '*'

jobs:
build:
# build stuff here to create release artifacts if needed

release:
name: gitchangelog-action
name: gitchangelog with gh-release action
runs-on: ubuntu-latest
steps:
- name: Get version
id: get_version
run: |
echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
echo ${{ VERSION }}

- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: gitchangelog action step
- name: Generate changes file
uses: sarnold/gitchangelog-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN}}
output_file: CHANGELOG.rst
config_file: .gitchangelog-custom.rc

- name: Create release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
name: Release ${{ env.VERSION }}
body_path: CHANGES.md
draft: true
prerelease: false


Input Options
Expand Down
6 changes: 4 additions & 2 deletions genchangelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ echo "Found: ${GIT_VERSION}"
NUM_TAGS=$(git tag -l | wc -l)
echo "Number of tags found: ${NUM_TAGS}"

CONFIG_FILE="/gitchangelog-release.rc"
if [[ -n "$INPUT_CONFIG_FILE" ]]; then
GITCHANGELOG_CONFIG_FILENAME="${INPUT_CONFIG_FILE}"
else
GITCHANGELOG_CONFIG_FILENAME="./.gitchangelog-release.rc"
GITCHANGELOG_CONFIG_FILENAME="${CONFIG_FILE}"
fi
export GITCHANGELOG_CONFIG_FILENAME="${GITCHANGELOG_CONFIG_FILENAME}"
echo "Config file: ${GITCHANGELOG_CONFIG_FILENAME}"

if [[ -n "$INPUT_OUTPUT_FILE" ]]; then
Expand All @@ -24,7 +26,7 @@ if [[ "${NUM_TAGS}" = "0" || "${NUM_TAGS}" = "1" ]]; then
echo "No previous tag found, generating full changelog ..."
CMD="gitchangelog --debug"
else
VERSION=${GITHUB_REF/refs\/tags\//}
[[ -n $VERSION ]] || VERSION=${GITHUB_REF/refs\/tags\//}
echo "Current version ref: ${VERSION}"
CURRENT_TAG="${VERSION}"
echo "If this is a tag, we use it: ${CURRENT_TAG}"
Expand Down
131 changes: 115 additions & 16 deletions .gitchangelog-release.rc → gitchangelog-release.rc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8; mode: python -*-
##
## Format
##
Expand Down Expand Up @@ -57,15 +58,15 @@
## will be ignored and won't be reported in the changelog.
##
ignore_regexps = [
r'@minor', r'!minor',
r'@cosmetic', r'!cosmetic',
r'@refactor', r'!refactor',
r'@wip', r'!wip',
r'^([cC]hg|[fF]ix|[nN]ew|[fF]eat)\s*:\s*[p|P]kg:',
r'^([cC]hg|[fF]ix|[nN]ew|[Ff]eat)\s*:\s*[d|D]ev:',
r'^(.{3,3}\s*:)?\s*[fF]irst commit.?\s*$',
r'^\d+\.\d+\.\d+$',
]
r'@minor', r'!minor',
r'@cosmetic', r'!cosmetic',
r'@refactor', r'!refactor',
r'@wip', r'!wip',
r'^([cC]hg|[fF]ix|[nN]ew)\s*:\s*[p|P]kg:',
r'^([cC]hg|[fF]ix|[nN]ew)\s*:\s*[d|D]ev:',
r'^(.{3,3}\s*:)?\s*[fF]irst commit.?\s*$',
r'^$', ## ignore commits with empty messages
]


## ``section_regexps`` is a list of 2-tuples associating a string label and a
Expand All @@ -81,15 +82,21 @@ ignore_regexps = [
## whenever you are tweaking this variable.
##
section_regexps = [
('New', [
r'^[nN]ew\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Features', [
r'^([nN]ew|[fF]eat)\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
r'^([nN]ew|[fF]eat)\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Changes', [
r'^[cC]hg\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),
('Fixes', [
r'^[fF]ix\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n]*)$',
]),

('Other', None ## Match all lines
),
]


Expand Down Expand Up @@ -120,12 +127,14 @@ section_regexps = [
##
## - strip: remove any spaces before or after the content of the string
##
## - SetIfEmpty(msg="No commit message."): will set the text to
## whatever given ``msg`` if the current text is empty.
##
## Additionally, you can `pipe` the provided filters, for instance:
#body_process = Wrap(regexp=r'\n(?=\w+\s*:)') | Indent(chars=" ")
#body_process = Wrap(regexp=r'\n(?=\w+\s*:)')
#body_process = noop
#body_process = ReSub(r'((^|\n)[A-Z]\w+(-\w+)*: .*(\n\s+.*)*)+$', r'') | strip
body_process = lambda text: ""
body_process = ReSub(r'((^|\n)[A-Z]\w+(-\w+)*: .*(\n\s+.*)*)+$', r'') | strip


## ``subject_process`` is a callable
Expand All @@ -135,18 +144,19 @@ body_process = lambda text: ""
##
## Available constructs are those listed in ``body_process`` doc.
subject_process = (strip |
ReSub(r'^([cC]hg|[fF]ix|[nN]ew|[fF]eat)\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n@]*)(@[a-z]+\s+)*$', r'\4') |
ucfirst | final_dot)
ReSub(r'^([cC]hg|[fF]ix|[nN]ew)\s*:\s*((dev|use?r|pkg|test|doc)\s*:\s*)?([^\n@]*)(@[a-z]+\s+)*$', r'\4') |
SetIfEmpty("No commit message.") | ucfirst | final_dot)


## ``tag_filter_regexp`` is a regexp
##
## Tags that will be used for the changelog must match this regexp.
##
tag_filter_regexp = r'^v?[0-9]+\.[0-9]+(\.[0-9]+)?$'
#tag_filter_regexp = r'^v?[0-9]+\.[0-9]+(\.[0-9]+)?$'
tag_filter_regexp = r'^[0-9]+\.[0-9]+(\.[0-9]+)?$'


## ``unreleased_version_label`` is a string
## ``unreleased_version_label`` is a string or a callable that outputs a string
##
## This label will be used as the changelog Title of the last set of changes
## between last valid tag and HEAD if any.
Expand All @@ -155,6 +165,7 @@ unreleased_version_label = "(unreleased)"
# ["git", "describe", "--tags"],
#shell=False)


## ``output_engine`` is a callable
##
## This will change the output format of the generated changelog file
Expand Down Expand Up @@ -194,3 +205,91 @@ output_engine = mustache("markdown")
## This option tells git-log whether to include merge commits in the log.
## The default is to include them.
include_merge = True


## ``log_encoding`` is a string identifier
##
## This option tells gitchangelog what encoding is outputed by ``git log``.
## The default is to be clever about it: it checks ``git config`` for
## ``i18n.logOutputEncoding``, and if not found will default to git's own
## default: ``utf-8``.
#log_encoding = 'utf-8'


## ``publish`` is a callable
##
## Sets what ``gitchangelog`` should do with the output generated by
## the output engine. ``publish`` is a callable taking one argument
## that is an interator on lines from the output engine.
##
## Some helper callable are provided:
##
## Available choices are:
##
## - stdout
##
## Outputs directly to standard output
## (This is the default)
##
## - FileInsertAtFirstRegexMatch(file, pattern, idx=lamda m: m.start(), flags)
##
## Creates a callable that will parse given file for the given
## regex pattern and will insert the output in the file.
## ``idx`` is a callable that receive the matching object and
## must return a integer index point where to insert the
## the output in the file. Default is to return the position of
## the start of the matched string.
##
## - FileRegexSubst(file, pattern, replace, flags)
##
## Apply a replace inplace in the given file. Your regex pattern must
## take care of everything and might be more complex. Check the README
## for a complete copy-pastable example.
##
# publish = FileInsertIntoFirstRegexMatch(
# "CHANGELOG.rst",
# r'/(?P<rev>[0-9]+\.[0-9]+(\.[0-9]+)?)\s+\([0-9]+-[0-9]{2}-[0-9]{2}\)\n--+\n/',
# idx=lambda m: m.start(1)
# )
#publish = stdout


## ``revs`` is a list of callable or a list of string
##
## callable will be called to resolve as strings and allow dynamical
## computation of these. The result will be used as revisions for
## gitchangelog (as if directly stated on the command line). This allows
## to filter exaclty which commits will be read by gitchangelog.
##
## To get a full documentation on the format of these strings, please
## refer to the ``git rev-list`` arguments. There are many examples.
##
## Using callables is especially useful, for instance, if you
## are using gitchangelog to generate incrementally your changelog.
##
## Some helpers are provided, you can use them::
##
## - FileFirstRegexMatch(file, pattern): will return a callable that will
## return the first string match for the given pattern in the given file.
## If you use named sub-patterns in your regex pattern, it'll output only
## the string matching the regex pattern named "rev".
##
## - Caret(rev): will return the rev prefixed by a "^", which is a
## way to remove the given revision and all its ancestor.
##
## Please note that if you provide a rev-list on the command line, it'll
## replace this value (which will then be ignored).
##
## If empty, then ``gitchangelog`` will act as it had to generate a full
## changelog.
##
## The default is to use all commits to make the changelog.
#revs = ["^1.0.3", ]
#revs = [
# Caret(
# FileFirstRegexMatch(
# "CHANGELOG.rst",
# r"(?P<rev>[0-9]+\.[0-9]+(\.[0-9]+)?)\s+\([0-9]+-[0-9]{2}-[0-9]{2}\)\n--+\n")),
# "HEAD"
#]
revs = []

0 comments on commit 9319f68

Please sign in to comment.