-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
201 lines (185 loc) · 6.37 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: 'relock-conda'
description: 'GitHub action to relock conda environments using conda-lock'
author: Matthew R. Becker and the regro-cf-autotick-bot team
branding:
icon: 'rotate-cw'
color: 'green'
inputs:
environment-file:
description: 'the environment to (re)lock'
required: false
default: environment.yml
lock-file:
description: 'the lock file to update'
required: true
default: 'conda-lock.yml'
ignored-packages:
description: 'comma- or newline-separated list of packages whose version changes are ignored when relocking'
required: true
default: ''
include-only-packages:
description: >
comma-or newline-separated list of packages to exclusively include when relocking, all others will be ignored,
ignored-packages is applied to this list
required: true
default: ''
relock-all-packages:
description: 'whether to relock on an update to any package in the environment, not just those in the environment file'
required: true
default: false
github-token:
description: 'GitHub personal access token to use for making PRs'
required: true
action:
description: >
the action to take if the lock file is updated: `pr` will make a PR; `file` will leave the updated lock file
in the current working directory
required: true
default: 'pr'
automerge:
description: 'whether to automatically merge the PR'
required: true
default: false
base-branch:
description: >
the base branch for PRs (See
[this documentation](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#events-which-checkout-a-commit)
for more details.)
head-branch:
description: 'the head branch for PRs'
required: true
default: 'relock-conda'
skip-if-pr-exists:
description: 'whether to skip relocking if a PR already exists'
required: true
default: false
draft:
description: 'whether to open the PR as a draft'
required: true
default: false
outputs:
pull-request-number:
description: "the number of the PR that was opened"
value: ${{ steps.pr.outputs.pull-request-number }}
relocked:
description: "whether the environment was relocked"
value: ${{ steps.set-output.outputs.relocked }}
runs:
using: "composite"
steps:
# https://stackoverflow.com/a/73828715/1745538
- name: skip if PR already exists
id: check
shell: bash -leo pipefail {0}
run: |
if [[ "${INPUT_ACTION}" != "pr" ]]; then
res="false"
else
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head '${{ inputs.head-branch }}' \
--json title \
--jq 'map(select(.title == "relock w/ conda-lock")) | length')
if [[ ${prs} != "0" && ${SKIP_IF_PR_EXISTS} == "true" ]]; then
res="true"
else
res="false"
fi
fi
echo "skip=${res}" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ inputs.github-token }}
SKIP_IF_PR_EXISTS: ${{ inputs.skip-if-pr-exists }}
INPUT_ACTION: ${{ inputs.action }}
- name: setup conda-lock
if: ${{ steps.check.outputs.skip != 'true' }}
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
with:
environment-name: relock-env
create-args: >-
python
click
ruamel.yaml
conda
conda-lock
condarc: |
channels:
- conda-forge
- name: relock
id: relock
if: ${{ steps.check.outputs.skip != 'true' }}
shell: bash -leo pipefail {0}
run: |
echo "::group::relock"
python ${{ github.action_path }}/relock.py \
--environment-file='${{ inputs.environment-file }}' \
--lock-file='${{ inputs.lock-file }}' \
--ignored-packages='${{ inputs.ignored-packages }}' \
--relock-all-packages='${{ inputs.relock-all-packages }}' \
--include-only-packages='${{ inputs.include-only-packages }}' \
> ${{ github.action_path }}/summary.txt
{
echo 'summary<<EOF'
cat ${{ github.action_path }}/summary.txt
echo EOF
} >> "$GITHUB_OUTPUT"
rm ${{ github.action_path }}/summary.txt
echo "::endgroup::"
- name: open PR
id: pr
if: >-
steps.check.outputs.skip != 'true'
&& steps.relock.outputs.env_relocked == 'true'
&& inputs.action == 'pr'
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6
with:
commit-message: relock w/ conda-lock
title: relock w/ conda-lock
body: "This pull request relocks the dependencies with conda-lock.
${{ steps.relock.outputs.summary }}"
branch: ${{ inputs.head-branch }}
delete-branch: true
token: ${{ inputs.github-token }}
labels: dependencies
base: ${{ inputs.base-branch }}
draft: ${{ inputs.draft }}
- name: automerge
if: >-
steps.check.outputs.skip != 'true'
&& inputs.automerge == 'true'
&& steps.relock.outputs.env_relocked == 'true'
&& steps.pr.outputs.pull-request-number != ''
&& inputs.action == 'pr'
shell: bash -leo pipefail {0}
run: gh pr merge --merge --auto "${{ steps.pr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ inputs.github-token }}
- name: set output
id: set-output
if: always()
shell: bash -leo pipefail {0}
run: |
res=""
# if we skipped, we did not relock
if [[ "${res}" == "" && '${{ steps.check.outputs.skip }}' == 'true' ]]; then
res="false"
fi
# if the env was relocked, then we look at PR vs file
if [[ "${res}" == "" && '${{ steps.relock.outputs.env_relocked }}' == 'true' ]]; then
# for a PR, we need to know if it was opened
if [[ '${{ inputs.action }}' == 'pr' ]]; then
if [[ '${{ steps.pr.outputs.pull-request-number }}' != '' ]]; then
res="true"
else
res="false"
fi
else
# if not a PR, then we updated the file
res="true"
fi
fi
# if we get here, default to false
if [[ "${res}" == "" ]]; then
res="false"
fi
echo "relocked=${res}" >> "$GITHUB_OUTPUT"