Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skip existing PRs #12

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,78 @@ jobs:
run: gh pr close ${{ steps.relock.outputs.pull-request-number }}
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

tests-skip-existing-part-1:
name: test skip existing part 1
needs: tests-no-lock
outputs:
pull-request-number: ${{ steps.relock.outputs.pull-request-number }}
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4

- 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 }}
automerge: false
base-branch: ${{ github.head_ref }}

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

- name: test that PR is OK
if: steps.relock.outputs.relocked == 'true'
shell: bash
run: |
gh pr checkout ${{ steps.relock.outputs.pull-request-number }}
ls -lah
if [ -f conda-lock.yml ]; then
: # do nothing
else
echo "conda-lock.yml not found"
exit 1
fi
grep numpy conda-lock.yml
grep python conda-lock.yml
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

tests-skip-existing-part-2:
name: test skip existing part 2
needs: tests-skip-existing-part-1
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4

- 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 }}
automerge: false
base-branch: ${{ github.head_ref }}
skip-if-pr-exists: true

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

- name: close PR
if: always()
continue-on-error: true
shell: bash
run: gh pr close ${{ needs.tests-skip-existing-part-1.outputs.pull-request-number }}
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ jobs:
# optional list of packages whose changes are ignore when relocking
# ignored-packages: "numpy,scipy"

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

# automerge the PR - you need to have GitHub automerge enabled to use this
# automerge the PR - you need to have GitHub automerge enabled
# 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: blah

# whether to skip relocking if a PR already exists
# skip-if-pr-exists: false # default
```

See the [action.yml](action.yml) for details on possible inputs and options.
34 changes: 30 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inputs:
the base branch for PRs (See
[this documentation](https:/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#events-which-checkout-a-commit)
for more details.)
skip-if-pr-exists:
description: 'whether to skip relocking if a PR already exists'
required: true
default: false

outputs:
pull-request-number:
Expand All @@ -46,7 +50,28 @@ outputs:
runs:
using: "composite"
steps:
- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
# https://stackoverflow.com/a/73828715/1745538
- name: skip if PR already exists
id: check
shell: bash -leo pipefail {0}
run: |
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head 'relock-conda' \
--json title \
--jq 'map(select(.title == "relock w/ conda-lock")) | length')
if [[ ${prs} != "0" && ${SKIP_IF_PR_EXISTS} == "true" ]]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ inputs.github-token }}
SKIP_IF_PR_EXISTS: ${{ inputs.skip-if-pr-exists }}

- name: setup conda-lock
if: ${{ steps.check.outputs.skip != 'true' }}
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
with:
environment-name: relock-env
create-args: >-
Expand All @@ -60,8 +85,9 @@ runs:
- conda-forge

- name: relock
shell: bash -leo pipefail {0}
id: relock
if: ${{ steps.check.outputs.skip != 'true' }}
shell: bash -leo pipefail {0}
run: |
python ${{ github.action_path }}/relock.py \
--environment-file=${{ inputs.environment-file }} \
Expand All @@ -79,7 +105,7 @@ runs:

- name: open PR
id: pr
if: steps.relock.outputs.relocked == 'true'
if: steps.check.outputs.skip != 'true' && steps.relock.outputs.relocked == 'true'
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6
with:
commit-message: relock w/ conda-lock
Expand All @@ -95,7 +121,7 @@ runs:
base: ${{ inputs.base-branch }}

- name: automerge
if: inputs.automerge == 'true' && steps.relock.outputs.relocked == 'true' && steps.pr.outputs.pull-request-number != ''
if: steps.check.outputs.skip != 'true' && inputs.automerge == 'true' && steps.relock.outputs.relocked == 'true' && steps.pr.outputs.pull-request-number != ''
shell: bash -leo pipefail {0}
run: gh pr merge --merge --auto "${{ steps.pr.outputs.pull-request-number }}"
env:
Expand Down
Loading