-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
177 lines (162 loc) · 6.54 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Open downstream PR if necessary
description: This action opens a PR against downstream repositories to update a library dependency.
inputs:
repository:
required: true
description: The downstream repository that consumes the library dependency.
token:
required: true
description: Github PAT used to open PRs. This token must have write access against the repository.
update-command:
required: true
description: The command run from the downstream repo that is used to update the library dependency.
working-directory:
required: false
default: ""
description: The relative directory in the downstream repo where all commands will run.
relevance-filter:
required: false
default: "- '**'"
description: A path filter used to determine if any relevant files where changed as a result of the `update-command`. By default, all changes are considered relevant.
reviewers:
required: false
description: A comma or newline-separated list of reviewers (GitHub usernames) to request a review from.
team-reviewers:
required: false
description: A comma or newline-separated list of GitHub teams to request a review from.
title:
required: false
description: The title of the pull request.
default: "[bot] Bump ${{github.event.repository.name}}"
committer:
required: false
description: The committer name and email address in the format Display Name <[email protected]>. Defaults to the GitHub Actions bot user.
default: "GitHub <[email protected]>"
author:
required: false
description: The author name and email address in the format Display Name <[email protected]>. Defaults to the user who triggered the workflow run.
default: "${{github.actor}} <${{github.actor}}@users.noreply.github.com>"
commit-message:
required: false
description: The message to use when committing changes.
default: "[bot] Bump ${{github.event.repository.name}}"
labels:
required: false
description: A comma or newline-separated list of labels.
default: bot
branch:
required: false
description: The pull request branch name.
default: bump-${{github.repository}}/patch
auto-merge:
required: false
description: Whether or not to enable "Auto-merge" on the pull request.
default: "false"
outputs:
pull-request-number:
description: "The pull request number"
value: ${{steps.create-pr.outputs.pull-request-number}}
pull-request-url:
description: "The URL of the pull request."
value: ${{steps.create-pr.outputs.pull-request-url}}
pull-request-operation:
description: "The pull request operation performed by the action, `created`, `updated` or `closed`."
value: ${{steps.create-pr.outputs.pull-request-description}}
pull-request-head-sha:
description: "The commit SHA of the pull request branch."
value: ${{steps.create-pr.outputs.pull-request-head-sha}}
runs:
using: composite
steps:
- name: Checkout ${{inputs.repository}}
uses: actions/checkout@v4
with:
repository: ${{inputs.repository}}
token: ${{inputs.token}}
path: ${{inputs.repository}}
- name: Set working directory
shell: bash
id: working-dir
run: |
if [ -z "${{inputs.working-directory}}" ]
then
echo "working_dir=${{inputs.repository}}" >> $GITHUB_ENV
else
echo "working_dir=${{inputs.repository}}/${{inputs.working-directory}}" >> $GITHUB_ENV
fi
- uses: actions/setup-go@v5
with:
go-version-file: ${{ env.working_dir }}/go.mod
cache: true
cache-dependency-path: ${{ env.working_dir }}/go.sum
- name: Setup git
shell: bash
run: |
git config --global url."https://${{inputs.token}}@github.com/".insteadOf https://github.com/
- name: Run update command
shell: bash
working-directory: ${{ env.working_dir }}
run: ${{inputs.update-command}}
# If the only files that changed are go.mod, go.sum, and vendor/modules.txt, then it's not worth a PR.
- name: Check if relevant files were changed
uses: dorny/[email protected]
id: changes
with:
working-directory: ${{ env.working_dir }}
base: HEAD
filters: |
relevant:
${{inputs.relevance-filter}}
- name: Construct PR body
shell: bash
run: |
cat << "EOT" >> /tmp/pr_body.txt
### Summary
This PR bumps [${{github.event.repository.name}}](https://github.com/${{github.repository}}) to pick up the most recent changes.
The following commands were run to generate this PR:
```sh
${{inputs.update-command}}
```
EOT
if [ "${{inputs.auto-merge}}" == "true" ]
then
echo "---" >> /tmp/pr_body.txt
echo "### Auto-merge enabled" >> /tmp/pr_body.txt
echo "This pull request will squash and merge automatically when all requirements are met." >> /tmp/pr_body.txt
echo "" >> /tmp/pr_body.txt
fi
echo "---" >> /tmp/pr_body.txt
echo "This PR was created by [${{github.workflow}}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) using [launchdarkly-labs/pr-downstream](https://github.com/launchdarkly-labs/pr-downstream)." >> /tmp/pr_body.txt
echo "pr_body<<EOF" >> $GITHUB_ENV
cat /tmp/pr_body.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create pull request
if: steps.changes.outputs.relevant == 'true'
uses: peter-evans/[email protected]
id: create-pr
with:
branch: ${{inputs.branch}}
path: ${{inputs.repository}}
reviewers: ${{inputs.reviewers}}
team-reviewers: ${{inputs.team-reviewers}}
delete-branch: true
commit-message: ${{inputs.commit-message}}
committer: ${{inputs.committer}}
author: ${{inputs.author}}
title: ${{inputs.title}}
body: ${{env.pr_body}}
labels: ${{inputs.labels}}
token: ${{inputs.token}}
- name: Check outputs
shell: bash
if: ${{ steps.create-pr.outputs.pull-request-url }}
run: |
echo "Successfully opened a PR: ${{ steps.create-pr.outputs.pull-request-url }}"
- name: Enable auto-merge
if: steps.changes.outputs.relevant == 'true' && inputs.auto-merge == 'true'
uses: peter-evans/[email protected]
with:
repository: ${{inputs.repository}}
token: ${{inputs.token}}
pull-request-number: ${{ steps.create-pr.outputs.pull-request-number }}
merge-method: squash