diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..caa32e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +*.iml \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1075362 --- /dev/null +++ b/action.yml @@ -0,0 +1,29 @@ +name: 'Auto changie' +description: 'Changie action with auto numbering' +inputs: + changie-version: + description: 'Changie version' + default: 'latest' + required: false +runs: + using: "composite" + steps: + - name: Setup node + uses: actions/setup-node@v4.0.2 + with: + node-version: 20 + + - name: Install changie + run: npm i -g changie@${{ input.changie-version }} + shell: bash + + - name: Set GitHub Path + run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH + shell: bash + env: + GITHUB_ACTION_PATH: ${{ github.action_path }} + + - name: Update changelog with last commit + run: script.sh + shell: bash + diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..18a4e56 --- /dev/null +++ b/script.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +if [ ! -f .changie.yaml ]; +then + echo "changie init" + changie init + # require to format unreleased file with more accurate name than seconds to avoid overriding file during multiple `changie new` in same seconds + echo "fragmentFileFormat: '{{.Kind}}-{{.Time.Format \"02012006-150405.000\"}}'" >> .changie.yaml +fi + +noRelease=$(cat CHANGELOG.md | grep 'No releases yet') + +# if never release take the first commit of all time +if [ -z "$noRelease" ]; +then + lastVersion=$(changie latest) + lastSeenCommit=$(cat .changes/$lastVersion.md | grep --only-matching --max-count 1 -E '\b[0-9a-f]{5,40}\b') +else + lastSeenCommit=$(git rev-list --max-parents=0 HEAD --abbrev-commit) +fi + +commit=$(git log --oneline --pretty=format:'%h - %s' --abbrev-commit $lastSeenCommit..HEAD) + +# deal with case of no new commit +if [ -n "$commit" ]; then + + # add all new commit as unreleased change + while IFS= read -r line ; do + echo "$line"; + changie new --kind Changed --body "$line" + done <<< "$commit" + + # group unreleased change in version file + changie batch auto | true + + # create changelog file + changie merge +fi +