Skip to content

⬆️ Update actions/upload-artifact action to v4.5.0 #269

⬆️ Update actions/upload-artifact action to v4.5.0

⬆️ Update actions/upload-artifact action to v4.5.0 #269

---
name: Sync template dependencies
# yamllint disable-line rule:truthy
on:
pull_request:
branches:
- main
workflow_dispatch:
env:
FILE_NAME: pyproject.toml.j2
jobs:
update-dependencies:
runs-on: ubuntu-latest
if: ${{ github.head_ref == 'renovate/lock-file-maintenance' || github.event_name == 'workflow_dispatch' }}
steps:
- name: ⤵️ Checkout Code
uses: actions/[email protected]
- name: 📝 Log the current file
run: |
cat template/${{ env.FILE_NAME }}
- name: ⤵️ Fetch Gist content
run: |
wget -O gist_content.txt https://gist.github.com/${{ secrets.GIST_ID }}/raw
cat gist_content.txt
- name: 🚀 Replace lines in file
run: |
FILE=template/pyproject.toml.j2
# Find the starting position (line number) of dev.dependencies
START_LINE=$(grep -n "dev.dependencies" $FILE | cut -d: -f1)
START_LINE=$(($START_LINE + 1))
# Find the end position (line number) of the first blank line after start position
END_LINE=$(awk -v start="$START_LINE" '/^$/ && NR > start {print NR-1; exit}' $FILE)
# Replace the lines between start and end position
awk -v start=$START_LINE -v end=$END_LINE '
NR < start || NR > end {print}
NR == start {
while ((getline < "gist_content.txt") > 0) {
if ($0) print
}
}
' $FILE > temp && mv temp $FILE
- name: 📝 Log the updated file
run: |
cat template/${{ env.FILE_NAME }}
- name: ⬆️ Upload artifact
uses: actions/[email protected]
with:
name: ${{ env.FILE_NAME }}
path: template/${{ env.FILE_NAME }}
check-on-changes:
needs: update-dependencies
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check-changes.outputs.changed }}
steps:
- name: ⤵️ Checkout Code
uses: actions/[email protected]
- name: ⤵️ Download artifact
uses: actions/[email protected]
with:
name: ${{ env.FILE_NAME }}
path: template
- name: 🔍 Check if file has changed
id: check-changes
run: |
if git diff --quiet -- template/${{ env.FILE_NAME }}; then
echo "No changes detected in ${{ env.FILE_NAME }}"
echo "changed=false" >> $GITHUB_OUTPUT
else
git diff -- template/${{ env.FILE_NAME }}
echo "Changes detected in ${{ env.FILE_NAME }}"
echo "changed=true" >> $GITHUB_OUTPUT
fi
commit-and-push:
needs: check-on-changes
if: needs.check-on-changes.outputs.changed == 'true'
runs-on: ubuntu-latest
steps:
- name: ⤵️ Checkout Code
uses: actions/[email protected]
with:
repository: ${{ github.event.repository.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: ⤵️ Download artifact
uses: actions/[email protected]
with:
name: ${{ env.FILE_NAME }}
path: template
- name: 🚀 Commit and push changes
uses: EndBug/[email protected]
with:
add: "template/${{ env.FILE_NAME }}"
message: "🔄 Sync dev dependencies from Github Gist"