-
Notifications
You must be signed in to change notification settings - Fork 7
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
POC: Combine slash-command-dispatch and conda-lock-command workflows #88
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# Runs conda-lock against environment.yml for reproducible environments | ||
# Runs on any opened PR | ||
# Runs on Pull Request comments starting with /condalock | ||
name: Conda Lock | ||
|
||
on: | ||
repository_dispatch: | ||
types: [condalock-command] | ||
|
||
permissions: # added using https://github.com/step-security/secure-workflows | ||
contents: read | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
condalock: | ||
# Only run on Pull Requests, when a comment with '/condalock' is made | ||
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/condalock') | ||
permissions: | ||
contents: write # for Git to git push | ||
contents: write # to git push added/changed files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately these permissions don't seem to transfer to a fork such that the conda-lock step can't commit the lockfile (https://github.com/weiji14/conda-lock-refresh-demo/actions/runs/6176646925/job/16766044554).
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We worked around this originally by using a personal access token https://github.com/pangeo-data/pangeo-docker-images/blob/df4252f60bfc798f57323bdd86f0348ffce8fa4c/.github/workflows/ChatOpsDispatcher.yml#L13 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was afraid that the default I've also considered setting up a GitHub App instead which has more permissions (https://docs.github.com/en/apps/creating-github-apps/about-creating-github-apps/deciding-when-to-build-a-github-app#choosing-between-a-github-app-or-github-actions), akin to what pre-commit CI is doing. That, or figuring out how conda-forge does it with their |
||
pull-requests: write # for adding reactions to pull request comments | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
defaults: | ||
|
@@ -27,45 +27,50 @@ jobs: | |
app_id: ${{ secrets.APP_ID }} | ||
private_key: ${{ secrets.APP_PRIVATE_KEY }} | ||
|
||
# Checkout the pull request branch | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
# Add an emoji reaction to comment to indicate the script is starting | ||
- name: Add reaction | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
token: ${{ steps.generate-token.outputs.token }} | ||
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} | ||
ref: ${{ github.event.client_payload.pull_request.head.ref }} | ||
repository: ${{ github.event.client_payload.github.payload.repository.full_name }} | ||
comment-id: ${{ github.event.comment.id }} | ||
reactions: eyes | ||
|
||
# Setup Python environment | ||
- uses: actions/setup-python@v4 | ||
# Checkout the git repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
python-version: '3.10' | ||
token: ${{ steps.generate-token.outputs.token }} | ||
|
||
# Install conda-lock library | ||
# HACK: Temporarily pin urllib3<2 to resolve incompatibilities: | ||
# https://github.com/ionrock/cachecontrol/issues/292 | ||
- name: Install conda-lock | ||
run: 'pip install conda-lock "urllib3<2"' | ||
# Switch to pull request branch | ||
# https://github.com/actions/checkout/issues/331#issuecomment-925405415 | ||
- name: Switch to Pull Request branch | ||
run: hub pr checkout ${{ github.event.issue.number }} | ||
env: | ||
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
|
||
# Run "conda-lock" for linux-64 only | ||
- name: Run conda-lock | ||
run: | | ||
conda-lock lock --mamba --kind explicit --file environment.yml --platform linux-64 | ||
# Add an emoji reaction to comment to indicate that conda-lock is starting | ||
- name: Add reaction | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
token: ${{ steps.generate-token.outputs.token }} | ||
repository: ${{ github.event.client_payload.github.payload.repository.full_name }} | ||
comment-id: ${{ github.event.comment.id }} | ||
reactions: rocket | ||
|
||
# Commit the change to the PR branch if any changes | ||
- name: Commit condalock files to PR | ||
run: | | ||
if [[ $(git ls-files --modified --others) ]]; then | ||
git config --global user.name 'actions-bot' | ||
git config --global user.email '[email protected]' | ||
git commit --all --message "[condalock-command] autogenerated conda-lock files" | ||
git push | ||
fi | ||
# Run conda-lock GitHub Action | ||
- name: Run conda-lock | ||
uses: weiji14/conda-lock-refresh@f021e17844c28aabfdb41c0ded96448043a8d2b5 # v0.1.0 | ||
with: | ||
file: "environment.yml" | ||
kind: "explicit" | ||
platform: "linux-64" | ||
|
||
# Add an emoji reaction to comment to indicate the script completed successfully | ||
- name: Add reaction | ||
uses: peter-evans/create-or-update-comment@v2 | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
token: ${{ steps.generate-token.outputs.token }} | ||
repository: ${{ github.event.client_payload.github.payload.repository.full_name }} | ||
comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | ||
reaction-type: hooray | ||
comment-id: ${{ github.event.comment.id }} | ||
reactions: hooray |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key part that ensures the workflow only runs on Pull Request comments starting with
/condalock
. Note that this can only run when theconda-lock-command.yml
workflow file is on the defaultmain
branch (see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment), so we'll need to merge this PR to test it.For a demo of how this works, see weiji14/conda-lock-refresh-demo#6 (comment).