Skip to content

Commit

Permalink
resuable workflow to automate pdm lock
Browse files Browse the repository at this point in the history
  • Loading branch information
kirtimanmishrazipstack committed Jul 17, 2024
1 parent d917bc1 commit 8a3f1f8
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 4 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Update PDM Lock Files

on:
push:


jobs:
backend_changes:
uses: ./.github/workflows/reusable-file-change-check.yaml
with:
file_path: backend/pyproject.toml

update-backend-pdm-lock:
needs: backend_changes
if: ${{ needs.backend_changes.outputs.changed == 'true' }}
uses: ./.github/workflows/reusable-update-pdm-lock.yaml
with:
service: 'backend'
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3

# - name: Check backend_changed value
# run: |
# echo "backend_changed value: ${{ needs.backend_changes.outputs.changed }}"

# - uses: ./.github/workflows/reusable-update-pdm-lock.yaml
# with:
# service: 'backend'

# update-prompt-service-pdm-lock:
# needs: changes
# if: ${{ needs.changes.outputs.prompt_service_changed == 'true' }}
# - uses: ./.github/workflows/update-pdm-lock.yml
# with:
# service: 'prompt-service'

# update-platform-service-pdm-lock:
# needs: changes
# if: ${{ needs.changes.outputs.platform_service_changed == 'true' }}
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Check platform_service_changed value
# run: |
# echo "platform_service_changed value: ${{ needs.changes.outputs.platform_service_changed }}"
# - uses: ./.github/workflows/update-pdm-lock.yml
# with:
# service: 'platform-service'

# update-root-pdm-lock:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: ./.github/workflows/update-pdm-lock.yml
# with:
# service: ''

# push-changes:
# needs: [update-backend-pdm-lock, update-prompt-service-pdm-lock, update-platform-service-pdm-lock, update-root-pdm-lock]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3

# - name: Push changes
# run: git push
# if: success()
33 changes: 33 additions & 0 deletions .github/workflows/reusable-file-change-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# file-change-check.yml
name: File Change Check

on:
workflow_call:
inputs:
file_path:
required: true
type: string
outputs:
changed:
description: "Indicates if the file has changed"
value: ${{ jobs.check_file_changes.outputs.changed }}

jobs:
check_file_changes:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check.outputs.changed }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Check file changes
id: check
run: |
echo "checking changes for "${{ inputs.file_path }}"";
echo "changed=false" >> $GITHUB_ENV
if git diff --name-only HEAD^ "${{ inputs.file_path }}" | grep -q "${{ inputs.file_path }}"; then
echo "changes in "${{ inputs.file_path }}"";
echo "changed=true" >> $GITHUB_OUTPUT
fi
59 changes: 59 additions & 0 deletions .github/workflows/reusable-update-pdm-lock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Update PDM Lock

on:
workflow_call:
inputs:
service:
description: 'Service directory to update pdm.lock. Leave empty for root.'
required: false
type: string

jobs:
update-lock:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install PDM
run: python -m pip install pdm

- name: Update and add pdm.lock
run: |
echo "inside udpate pdm ${{ inputs.service }}";
if [ -n "${{ inputs.service }}" ]; then
cd ${{ inputs.service }}
fi
pdm venv create -w virtualenv --with-pip
source .venv/bin/activate
pdm lock
# Debugging output
echo "curent dir: "; pwd
echo "Listing files in ${{ inputs.service || 'root' }} directory:"; ls -al | grep pdm.lock
git add pdm.lock
- name: Commit pdm.lock
run: |
echo "Dir: "; pwd
echo "LFiles in ${{ inputs.service || 'root' }} directory:"; ls -al
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
pdm venv create -w virtualenv --with-pip
source .venv/bin/activate
pip install pre-commit~=3.6.2
git add .pre-commit-config.yaml
pre-commit run
if [ -n "${{ inputs.service }}" ]; then
git commit -m "Update pdm.lock for ${{ inputs.service }}"
else
git commit -m "Update pdm.lock for root directory"
fi
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ repos:
entry: pyupgrade --py39-plus --keep-runtime-typing
types:
- python
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
hooks:
- id: gitleaks
# - repo: https://github.com/gitleaks/gitleaks
# rev: v8.18.4
# hooks:
# - id: gitleaks
# - repo: https://github.com/hadolint/hadolint
# rev: v2.12.1-beta
# hooks:
Expand Down

0 comments on commit 8a3f1f8

Please sign in to comment.