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

Adding Github action to regenerate Lockfile #1506

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
83 changes: 83 additions & 0 deletions .github/workflows/lock-deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# https://docs.github.com/en/actions/using-workflows/reusing-workflows#calling-a-reusable-workflow
# https://docs.github.com/fr/actions/using-workflows/workflow-syntax-for-github-actions#exemple--inclusion-de-chemins-dacc%C3%A8s

name: Lock dependencies
on:
pull_request:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be paths: pointing to pyproject.toml, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was basing it on a label, to regenerate the lockfile only on demand, either on PR, or by running the action.

types: [opened, reopened, synchronize, labeled, unlabeled]
workflow_dispatch:
# Concurrency : auto-cancel "old" jobs ie when pushing again
# https://docs.github.com/fr/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
defaults:
run:
shell: bash
permissions:
pull-requests: write
contents: write

jobs:
lock-deps:
if: ${{ !github.event.pull_request || contains( github.event.pull_request.labels.*.name, 'Lockfile') }}
name: "Lock dependencies using PDM"
runs-on: ubuntu-latest
continue-on-error: false # https://ncorti.com/blog/howto-github-actions-build-matrix
steps:
- name: Check if organization member
id: is_organization_member
uses: JamesSingleton/[email protected]
with:
organization: Giskard-AI
username: ${{ github.actor }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Interrupt job
if: ${{ steps.is_organization_member.outputs.result == 'false' }}
shell: bash
run: |
echo "Job failed due to user not being a member of Giskard-AI organization and the 'safe for build' label not being set on the PR"
exit 1

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Checkout code
uses: actions/[email protected]
with:
token: ${{ secrets.RELEASE_PAT_TOKEN }} # Needed to trigger other actions
ref: ${{ steps.extract_branch.outputs.branch }}

- name: Setup PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: "3.10"
cache: false

- name: Install dependencies
run: rm -rf pdm.lock && pdm lock -G :all

- name: Configure git
run: |
git config --global user.name 'BotLocker'
git config --global user.email '[email protected]'

- name: Adding file
run: |
git add pdm.lock
git commit -m "Regenerating pdm.lock" --allow-empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why --allow-empty ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it's fine to get an empty commit if the lock is already up to date, to show it's been regenerating either way


- name: Remove label
if: ${{ github.event.pull_request}}
run: |
gh pr edit --remove-label Lockfile
env:
GH_TOKEN: ${{ github.token }}

- name: Push to target branch
run: |
git push origin ${{ steps.extract_branch.outputs.branch }}

110 changes: 54 additions & 56 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.