stiil onm fiole change #22
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
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 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' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
echo "current root dir: "; pwd | |
echo "files in root dir: "; ls -al | |
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 | |
git add .pre-commit-config.yaml | |
pre-commit run pdm-lock-check | |
git commit -m "Update pdm.lock for ${{ matrix.directory }}" | |
git push origin ${{ github.ref_name }} |