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: add first version of action #1

Merged
merged 31 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
31f803a
feat: add first vcersion of action
beckermr Aug 27, 2024
352c956
doc: added tests badge
beckermr Aug 27, 2024
2ee6228
feat: make sure works without existing lock file
beckermr Aug 27, 2024
4f81818
doc: more text
beckermr Aug 27, 2024
a4d1b11
chore: add pre-commit
beckermr Aug 27, 2024
82f850f
chore: get pre-commit running
beckermr Aug 27, 2024
4afe794
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
808d634
doc: add pre-commit badge
beckermr Aug 27, 2024
b6af24e
Merge branch 'first-commit' of https:/beckermr/relock-con…
beckermr Aug 27, 2024
d613bbc
test: try a simple smoke test
beckermr Aug 27, 2024
8a2f407
test: try this
beckermr Aug 27, 2024
2361e61
test: maybe need v4
beckermr Aug 27, 2024
0ec8176
test: ensure have a proper base
beckermr Aug 27, 2024
59f8dde
fix: wrong input
beckermr Aug 27, 2024
e811921
fix: wrong name
beckermr Aug 27, 2024
bff24e2
fix: wrong input again
beckermr Aug 27, 2024
fa038e2
fix: ensure token has permissions
beckermr Aug 27, 2024
d1b6975
fix: use a pat
beckermr Aug 27, 2024
b77fd08
fix: bugs
beckermr Aug 27, 2024
e89ae65
test: see what is here
beckermr Aug 27, 2024
902a4ab
try this again
beckermr Aug 27, 2024
5e3e4bd
fix: skip if did not relock
beckermr Aug 27, 2024
fc6b99c
fix: ruff it up
beckermr Aug 27, 2024
6e3d026
what is here
beckermr Aug 27, 2024
1941bd6
test: fix the tests again and add outputs
beckermr Aug 27, 2024
faa0aea
test: do not run on own PRs
beckermr Aug 27, 2024
75f778b
test: add test for no relocking
beckermr Aug 27, 2024
db664e1
final bit of cleanup
beckermr Aug 27, 2024
5f0b24c
test: try again
beckermr Aug 27, 2024
824b20d
test: only run one at a time
beckermr Aug 27, 2024
60826c2
try this
beckermr Aug 27, 2024
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
106 changes: 106 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: tests

on:
push:
branches:
- main
pull_request: null

concurrency:
group: tests
cancel-in-progress: false

jobs:
tests-lock:
name: test updates
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: 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 }}

- 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 }}

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:
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.11
channels: conda-forge
channel-priority: strict
show-channel-urls: true
miniforge-version: latest

- name: make the lock file
shell: bash -leo pipefail {0}
run: |
conda install --yes conda-lock
conda-lock lock --file test-env.yml --lockfile conda-lockk.yml

- name: relock
id: relock
uses: ./
with:
environment-file: test-env.yml
lock-file: conda-lockk.yml
ignored-packages: ''
relock-all-packages: false
github-token: ${{ secrets.GH_PAT }}
automerge: false
base-branch: ${{ github.head_ref }}

- 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 }}
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https:/astral-sh/ruff-pre-commit
rev: v0.5.6
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
autofix_prs: false
autoupdate_commit_msg: '[ci skip] [pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: monthly
skip: []
submodules: false
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# relock-conda
[![tests](https:/beckermr/relock-conda/actions/workflows/tests.yml/badge.svg)](https:/beckermr/relock-conda/actions/workflows/tests.yml) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/beckermr/relock-conda/main.svg)](https://results.pre-commit.ci/latest/github/beckermr/relock-conda/main)

GitHub action to relock conda environments using conda-lock

This action runs [conda-lock](https:/conda/conda-lock) to relock a conda environment and makes a PR
with the changes if any are found. By default, a PR is only made if a package list in the input `environment.yml`
file is updated.

## Usage

```yaml
name: relock conda
on:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
name: test
steps:
- name: run
uses: beckermr/relock-conda@main
with:
# A GitHub personal access token is required
github-token: ${{ secrets.GITHUB_PAT }}

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

# 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
# relock-all-packages: false # default

# automerge the PR - you need to have GitHub automerge enabled to use this
# automerge: false # default
```

See the [action.yml](action.yml) for details on possible inputs and options.
102 changes: 102 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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-separated list of packages whose version changes are ignored when relocking'
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
automerge:
description: 'whether to automatically merge the PR'
required: true
default: false
base-branch:
description: >
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.)

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.relock.outputs.relocked }}

runs:
using: "composite"
steps:
- 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
shell: bash -leo pipefail {0}
id: relock
run: |
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 }} \
> ${{ 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

- name: open PR
id: pr
if: steps.relock.outputs.relocked == 'true'
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: relock-conda
delete-branch: true
token: ${{ inputs.github-token }}
labels: dependencies
base: ${{ inputs.base-branch }}

- name: automerge
if: 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:
GH_TOKEN: ${{ inputs.github-token }}
Loading
Loading