Skip to content

testing pdm version on workflow #38

testing pdm version on workflow

testing pdm version on workflow #38

name: Automate pdm.lock
on: push
jobs:
check_pyproject_changes:
runs-on: ubuntu-latest
strategy:
matrix:
directory: [backend, prompt-service, root]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check file changes
id: check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ matrix.directory }}" = "root" ]; then
file_path="pyproject.toml"
else
file_path="${{ matrix.directory }}/pyproject.toml"
fi
echo "checking changes for $file_path for origin/main branch"
echo "changed=false" >> $GITHUB_OUTPUT
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git fetch origin
if git diff --quiet origin/main -- "$file_path"; then
echo "No changes detected in $file_path against origin/main branch."
else
echo "Changes detected in $file_path against origin/main branch."
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Set up Python
if: steps.check.outputs.changed == 'true'
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Set up Go
if: steps.check.outputs.changed == 'true'
uses: actions/setup-go@v4
with:
go-version: '1.22.5'
- name: Install PDM
if: steps.check.outputs.changed == 'true'
run: python -m pip install pdm==2.16.1
- name: Update and add pdm.lock
if: steps.check.outputs.changed == 'true'
run: |
if [ "${{ matrix.directory }}" != "root" ]; then
cd ${{ matrix.directory }}
fi
if [ ! -d ".venv" ]; then
echo 'Creating virtual environment inside "${{ matrix.directory }}".'
pdm venv create -w virtualenv --with-pip
else
echo "Virtual environment already exists."
fi
source .venv/bin/activate
pdm lock -G :all
git add pdm.lock
- name: Commit and push pdm.lock
if: steps.check.outputs.changed == 'true'
id: check_commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ ! -d ".venv" ]; then
echo "Creating virtual environment inside root"
pdm venv create -w virtualenv --with-pip
else
echo "Virtual environment already exists."
fi
source .venv/bin/activate
pip install pre-commit~=3.6.2
pre-commit run pdm-lock-check
if git diff --quiet; then
echo "No changes in compared to the SELF branch."
echo "Nothing to commit"
else
echo "Changes detected in compared to the SELF branch."
git commit -m "Update pdm.lock for ${{ matrix.directory }}"
git push origin ${{ github.ref_name }}
fi