Skip to content

Commit

Permalink
feat: leave file in tree
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Sep 2, 2024
1 parent 42a320e commit 76b2ac2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 11 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,39 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

tests-file:
name: test updates w/ file
runs-on: "ubuntu-latest"
if: github.event.pull_request.title != 'relock w/ conda-lock'
steps:
- uses: actions/checkout@v4

- name: make a copy of lock file
shell: bash -leo pipefail {0}
run: |
cp conda-lock.yml old-conda-lock.yml
- name: relock
id: relock
uses: ./
with:
environment-file: test-env.yml
lock-file: conda-lock.yml
ignored-packages: ''
relock-all-packages: false
github-token: ${{ secrets.GH_PAT }}
action: file

- name: did it relock?
if: steps.relock.outputs.relocked != 'true'
run: exit 1

- name: test that lock file is different
if: steps.relock.outputs.relocked == 'true'
shell: bash
run: |
diff conda-lock.yml old-conda-lock.yml && exit 0 || exit 1
tests-no-lock:
name: test no update
runs-on: "ubuntu-latest"
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,40 @@ jobs:
github-token: ${{ secrets.GITHUB_PAT }}

# files to relock w/ conda-lock
# environment-file: environment.yml # default
# lock-file: conda-lock.yml # default
environment-file: environment.yml # default
lock-file: conda-lock.yml # default

# optional list of packages whose changes are ignore when relocking
ignored-packages: "" # default
# ignored-packages: "numpy,scipy"

# use only these packages to determine if a relock is needed
include-only-packages: "" # default
# include-only-packages: "numpy,scipy"

# whether to relock on an update to any package in the environment,
# not just those in the environment file
# relock-all-packages: false # default
relock-all-packages: false # default

# action to take if we relock
# one of 'pr' (make a PR) or 'file' (leave new lock file in CWD)
action: 'pr' # default

# these options apply only if we are making PRs
# automerge the PR - you need to have GitHub automerge enabled
# automerge: false # default
automerge: false # default

# use this setting to fix issues with the base branch not
# being inferred correctly
# See https:/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#events-which-checkout-a-commit
base-branch: "" # default
# base-branch: blah

# the head branch for PRs
# head-branch: relock-conda # default
head-branch: relock-conda # default

# whether to skip relocking if a PR already exists
# skip-if-pr-exists: false # default
skip-if-pr-exists: false # default
```
See the [action.yml](action.yml) for details on possible inputs and options.
49 changes: 44 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ inputs:
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
Expand Down Expand Up @@ -63,6 +69,7 @@ runs:
# https://stackoverflow.com/a/73828715/1745538
- name: skip if PR already exists
id: check
if: inputs.action == 'pr'
shell: bash -leo pipefail {0}
run: |
prs=$(gh pr list \
Expand All @@ -79,6 +86,13 @@ runs:
GH_TOKEN: ${{ inputs.github-token }}
SKIP_IF_PR_EXISTS: ${{ inputs.skip-if-pr-exists }}

- name: do not skip for non-PR actions
id: check
if: inputs.action != 'pr'
shell: bash -leo pipefail {0}
run: |
echo "skip=false" >> "$GITHUB_OUTPUT"
- name: setup conda-lock
if: ${{ steps.check.outputs.skip != 'true' }}
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
Expand Down Expand Up @@ -117,7 +131,10 @@ runs:
- name: open PR
id: pr
if: steps.check.outputs.skip != 'true' && steps.relock.outputs.env_relocked == 'true'
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
Expand All @@ -133,7 +150,12 @@ runs:
base: ${{ inputs.base-branch }}

- name: automerge
if: steps.check.outputs.skip != 'true' && inputs.automerge == 'true' && steps.relock.outputs.env_relocked == 'true' && steps.pr.outputs.pull-request-number != ''
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:
Expand All @@ -144,10 +166,27 @@ runs:
if: always()
shell: bash -leo pipefail {0}
run: |
# if we skipped, we did not relock
if [[ '${{ steps.check.outputs.skip }}' == 'true' ]]; then
echo "relocked=false" >> "$GITHUB_OUTPUT"
elif [[ '${{ steps.relock.outputs.env_relocked }}' == 'true' && '${{ steps.pr.outputs.pull-request-number }}' != '' ]]; then
exit 0
fi
if [[ '${{ 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
echo "relocked=true" >> "$GITHUB_OUTPUT"
else
echo "relocked=false" >> "$GITHUB_OUTPUT"
fi
exit 0
fi
# for a file, we know it was relocked
echo "relocked=true" >> "$GITHUB_OUTPUT"
else
echo "relocked=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# if we get here then it did not relock
echo "relocked=false" >> "$GITHUB_OUTPUT"

0 comments on commit 76b2ac2

Please sign in to comment.