Skip to content

Commit

Permalink
add sync requirements workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
julien777z committed Feb 8, 2025
1 parent 628fada commit ef8d134
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/poetry-lock-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Sync Requirements

on:
push:
paths:
- 'poetry.lock'
workflow_dispatch:

jobs:
sync_requirements:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Poetry and plugin
run: |
pip install poetry==2.0.1
poetry self add poetry-plugin-export
- name: Configure Git credentials
run: |
echo "https://${{ secrets.BLOXLINK_LIB_ACCESS }}:@github.com" > $HOME/.git-credentials
git config --global credential.helper store
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
env:
POETRY_HTTP_BASIC_BLOXLINK_LIB_USERNAME: "{${{ secrets.BLOXLINK_LIB_ACCESS }}}"

- name: Update requirements.txt
run: poetry export --without-hashes --format=requirements.txt > requirements.txt

- name: Check for changes
id: changes
run: |
if [[ -n "$(git status --porcelain requirements.txt)" ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push if changed
if: steps.changes.outputs.changed == 'true'
run: |
git add requirements.txt
git commit -m "chore: sync requirements.txt with poetry.lock"
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# Push to the PR branch
git push origin HEAD:${{ github.head_ref }}
else
# Push to main
git push
fi
- name: Cleanup credentials
if: always()
run: rm -f $HOME/.git-credentials

0 comments on commit ef8d134

Please sign in to comment.