diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1a0010c..7aae71c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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" diff --git a/README.md b/README.md index 7af0c9f..f54d04d 100644 --- a/README.md +++ b/README.md @@ -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://github.com/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. diff --git a/action.yml b/action.yml index d3187a7..fd535c8 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 \ @@ -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 @@ -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 @@ -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: @@ -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"