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

fix: bug in parsing inputs, add head branch option, fix relock output #32

Merged
merged 9 commits into from
Sep 1, 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
41 changes: 39 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
github-token: ${{ secrets.GH_PAT }}
automerge: false
base-branch: ${{ github.head_ref }}
head-branch: tests-lock

- name: did it relock?
if: steps.relock.outputs.relocked != 'true'
Expand Down Expand Up @@ -91,7 +92,6 @@ jobs:

tests-no-lock:
name: test no update
needs: tests-lock
runs-on: "ubuntu-latest"
if: github.event.pull_request.title != 'relock w/ conda-lock'
steps:
Expand Down Expand Up @@ -122,6 +122,7 @@ jobs:
github-token: ${{ secrets.GH_PAT }}
automerge: false
base-branch: ${{ github.head_ref }}
head-branch: tests-no-lock

- name: did it not relock?
if: steps.relock.outputs.relocked == 'true'
Expand All @@ -137,10 +138,10 @@ jobs:

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"
if: github.event.pull_request.title != 'relock w/ conda-lock'
steps:
- uses: actions/checkout@v4

Expand All @@ -155,6 +156,7 @@ jobs:
github-token: ${{ secrets.GH_PAT }}
automerge: false
base-branch: ${{ github.head_ref }}
head-branch: tests-skip-existing

- name: did it relock?
if: steps.relock.outputs.relocked != 'true'
Expand All @@ -181,6 +183,7 @@ jobs:
name: test skip existing part 2
needs: tests-skip-existing-part-1
runs-on: "ubuntu-latest"
if: github.event.pull_request.title != 'relock w/ conda-lock'
steps:
- uses: actions/checkout@v4

Expand All @@ -195,6 +198,7 @@ jobs:
github-token: ${{ secrets.GH_PAT }}
automerge: false
base-branch: ${{ github.head_ref }}
head-branch: tests-skip-existing
skip-if-pr-exists: true

- name: did it relock?
Expand All @@ -209,3 +213,36 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GH_PAT }}

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

- name: relock
id: relock
uses: ./
with:
environment-file: test-env.yml
lock-file: outdated-conda-lock.yml
relock-all-packages: false
github-token: ${{ secrets.GH_PAT }}
automerge: false
base-branch: ${{ github.head_ref }}
head-branch: tests-ignore
ignored-packages: |
python
numpy

- name: did it not 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 ${{ steps.relock.outputs.pull-request-number }}
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
# optional list of packages whose changes are ignore when relocking
# ignored-packages: "numpy,scipy"

# use only these packages to determine if a relock is needed
# 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
Expand All @@ -44,6 +47,9 @@ jobs:
# See https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#events-which-checkout-a-commit
# base-branch: blah

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

# whether to skip relocking if a PR already exists
# skip-if-pr-exists: false # default
```
Expand Down
40 changes: 29 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ inputs:
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
Expand All @@ -51,7 +55,7 @@ outputs:
value: ${{ steps.pr.outputs.pull-request-number }}
relocked:
description: "whether the environment was relocked"
value: ${{ steps.relock.outputs.relocked }}
value: ${{ steps.set-output.outputs.relocked }}

runs:
using: "composite"
Expand All @@ -63,7 +67,7 @@ runs:
run: |
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head 'relock-conda' \
--head '${{ inputs.head-branch }}' \
--json title \
--jq 'map(select(.title == "relock w/ conda-lock")) | length')
if [[ ${prs} != "0" && ${SKIP_IF_PR_EXISTS} == "true" ]]; then
Expand Down Expand Up @@ -95,24 +99,25 @@ runs:
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 }} \
--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
ls -lah
echo "::endgroup::"

- name: open PR
id: pr
if: steps.check.outputs.skip != 'true' && steps.relock.outputs.relocked == 'true'
if: steps.check.outputs.skip != 'true' && steps.relock.outputs.env_relocked == 'true'
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6
with:
commit-message: relock w/ conda-lock
Expand All @@ -121,15 +126,28 @@ runs:


${{ steps.relock.outputs.summary }}"
branch: relock-conda
branch: ${{ inputs.head-branch }}
delete-branch: true
token: ${{ inputs.github-token }}
labels: dependencies
base: ${{ inputs.base-branch }}

- name: automerge
if: steps.check.outputs.skip != 'true' && 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.env_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:
GH_TOKEN: ${{ inputs.github-token }}

- name: set output
id: set-output
if: always()
shell: bash -leo pipefail {0}
run: |
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
echo "relocked=true" >> "$GITHUB_OUTPUT"
else
echo "relocked=false" >> "$GITHUB_OUTPUT"
fi
Loading
Loading