Skip to content

Commit

Permalink
fixup! ci: add compile-pip-reqs.yml workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
thst-nordic committed Sep 21, 2023
1 parent 9330da2 commit b768b85
Showing 1 changed file with 27 additions and 45 deletions.
72 changes: 27 additions & 45 deletions .github/workflows/compile-pip-reqs.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: Compile pip requirements and push to PR branch
name: Compile requirement-fixed.txt and push to PR branch

on:
pull_request_target:
paths:
- 'scripts/requirements-ci.txt'
# paths-ignore:
# - 'scripts/requirement-fixed.txt'
# types: [opened, synchronize, reopened, ready_for_review, edited]
# - 'scripts/requirements.txt'
# - 'scripts/requirements-base.txt'
# - 'scripts/requirements-build.txt'
- 'scripts/requirements.txt'
- 'scripts/requirements-base.txt'
- 'scripts/requirements-build.txt'

permissions:
contents: write
Expand All @@ -19,23 +16,19 @@ jobs:
runs-on: ubuntu-20.04

steps:
- name: Checkout
- name: Checkout PR target branch
uses: actions/checkout@v4
with:
token: ${{ secrets.NCS_GITHUB_TOKEN }}
path: ncs/nrf
fetch-depth: 1

- name: Checkout PR
- name: Switch to PR source branch
working-directory: ncs/nrf
env:
GITHUB_TOKEN: ${{ secrets.NCS_GITHUB_TOKEN }}
run: gh pr checkout ${{ github.event.pull_request.number }}

# - name: Create report file
# working-directory: ncs/nrf
# run: date +%s > scripts/requirement-fixed.txt

- name: Get python version
id: pyv
run: |
Expand All @@ -56,41 +49,17 @@ jobs:
west init -l nrf
west update mcuboot zephyr
- name: Generate new requirements-fixed.txt
- name: Compile new requirements-fixed.txt
working-directory: ncs
run: nrf/scripts/compile-requirements.sh requirements-fixed.txt
run: nrf/scripts/compile-requirements.sh ncs/nrf/scripts/requirements-fixed.txt

- name: Store requirements-fixed
uses: actions/upload-artifact@v3
with:
name: requirements-fixed
path: ncs/requirements-fixed.txt

- name: Compare requirements-fixed
id: diff
run: |
NEW=ncs/requirements-fixed.txt
OLD=ncs/nrf/scripts/requirements-fixed.txt
DIFF_OUTPUT=$(diff -EZbwByd --suppress-common-lines $NEW $OLD) || true # Add || true to avoid step failure
echo "DIFF_OUTPUT"
echo $DIFF_OUTPUT
if [[ -n "$DIFF_OUTPUT" ]]; then
echo "Differences found! Making autocommit"
echo "difference=true" >> $GITHUB_OUTPUT
echo '${{ steps.diff.outputs.difference }}'
cp $NEW $OLD
else
echo "No differences found."
echo "difference=false" >> $GITHUB_OUTPUT
fi
echo '${{ steps.diff.outputs.difference }}'
cd ncs/nrf
git log -n 5
path: ncs/nrf/scripts/requirements-fixed.txt

- name: Commit and push changes
if: ${{ steps.diff.outputs.difference == 'true' }}
- name: Push Changes to PR branch if different
working-directory: ncs/nrf
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -99,7 +68,20 @@ jobs:
git config user.name "NordicBuilder"
git add -A
git commit -s -m "Updating scripts/requirements-fixed.txt with new fixed versions" -m 'This is an automated commit from github workflow by NordicBuilder'
git push
git diff HEAD~1 \
--exit-code \
--ignore-space-change \
--ignore-all-space \
--ignore-blank-lines \
--ignore-cr-at-eol \
--ignore-space-at-eol
# Check the return code ($?) and exit if it's 0
if [ $? -eq 0 ]; then
echo "No differences found."
exit 0
else
echo "Differences found! Pushing changes to PR branch."
git push
fi

0 comments on commit b768b85

Please sign in to comment.