-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
107 lines (99 loc) · 4.7 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# **what?**
# Add a changelog yaml file per changie expectation when a bot creates a PR. The new yaml file
# will be created if none already exists on the PR when the PR has a specifed label. Once created,
# it will be committed by a specified bot and commit will be pushed to the PR.
#
# **why?**
# Automate changelog generation for more visability with automated bot changes.
# **when?**
# Once a PR is created and it has been correctly labeled.
#
# An exampe use is for PRs created by dependabot. You can also manually trigger this by adding the
# specified label at any time.
#
# Assumptions
# 1. You're using changie
# 2. Your changelogs live in the default `.changes. path, nothing custom
# 3. This action is called in the context of a PR
# 4. Not changelog yaml file already exists on this PR
# 5. This PR already exists and you just need to add a commit with the changelog to it
#
# A note on tokens:
# When using the GITHUB_TOKEN, the resulting commit will not trigger another GitHub Actions
# Workflow run. This is due to limitations set by GitHub.
# See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
# When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions
# app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents
# you from accidentally creating recursive workflow runs. To get around this, use a Personal
# Access Token to commit changes.
name: Automated Changelog Generation for changie
description: Generate a changelog yaml file in a format expected by changie for bot driven PRs.
inputs:
GITHUB_TOKEN:
description: Token to use to commit the file. If you use the GITHUB_TOKEN this commit will not retrigger workflows. Use a PAT to cause the commit to re-trigger workflows.
required: true
commit_author_name:
description: Author name for the commit
required: true
commit_author_email:
description: Author email for the commit
required: true
commit_message:
description: Message to put on commit of new changelog file
required: false
default: "Add automated changelog yaml from template"
changie_kind:
description: Type of changelog file # TODO: how does changie define this?
required: true
label:
description: GitHub label to trigger off of
required: true
custom_changelog_string: # use changie commands once available
description: The multi-line string containing the expected contents of the custom fields for a changelog entry.
required: false
runs:
using: "composite"
steps:
- name: Checkout Branch
if: ${{ contains(github.event.pull_request.labels.*.name, inputs.label ) }}
uses: actions/checkout@v3
with:
# specifying the ref avoids checking out the repository in a detached state
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ inputs.GITHUB_TOKEN }}
- name: Check if changelog file exists already
# if there's already a changelog entry, don't add another one!
if: ${{ contains(github.event.pull_request.labels.*.name, inputs.label ) }}
shell: bash
id: changelog_check
run: |
git fetch origin ${{ github.event.pull_request.base.ref }}
declare RESULT=$(git diff --name-only ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.base.sha }})
echo $RESULT
if echo $RESULT | grep '.changes/unreleased/.*.yaml'; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Changelog already exists for this PR, skip creating a new one"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "No changelog exists for this PR, creating a new one"
fi
- name: Create file from template
if: ${{ steps.changelog_check.outputs.exists == 'false' && contains(github.event.pull_request.labels.*.name, inputs.label ) }}
shell: bash
run: |
FILEPATH=.changes/unreleased/${{ inputs.changie_kind }}-$(date +%Y%m%d-%H%M%S).yaml
echo 'kind: "${{ inputs.changie_kind }}"' > $FILEPATH
echo 'body: "${{ github.event.pull_request.title }}"' >> $FILEPATH
echo "time: $(date +%Y-%m-%dT%H:%M:%S.00000Z)" >> $FILEPATH
echo "${{ inputs.custom_changelog_string }}" >> $FILEPATH
- name: Commit & Push changes
if: ${{ steps.changelog_check.outputs.exists == 'false' && contains(github.event.pull_request.labels.*.name, inputs.label ) }}
shell: bash
run: |
git status
git config user.name '${{ inputs.commit_author_name }}'
git config user.email '${{ inputs.commit_author_email }}'
git pull
git add .
git commit -m "${{ inputs.commit_message }}"
git push