Skip to content

Commit

Permalink
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 22, 2023
1 parent 327fae6 commit 421d585
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/compile-pip-reqs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Compile requirements-fixed.txt and push to PR

on:
pull_request_target:
paths:
- 'scripts/requirements.txt'
- 'scripts/requirements-ci.txt'
- 'scripts/requirements-base.txt'
- 'scripts/requirements-build.txt'

permissions:
contents: write

jobs:
fix-requirements:
runs-on: ubuntu-20.04

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

- 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: Get python version
id: pyv
run: |
sudo snap install --channel=v4 yq
PYTHON_VERSION=$(yq '.python.version' ./ncs/nrf/scripts/tools-versions-linux.yml)
echo "python_version=$PYTHON_VERSION" >> $GITHUB_OUTPUT
- name: Setup python version
uses: actions/setup-python@v4
with:
python-version: '${{ steps.pyv.outputs.python_version }}'

- name: Setup environment
working-directory: ncs
run: |
pip3 install --user -U setuptools wheel pip virtualenv virtualenvwrapper
pip3 install -r nrf/scripts/requirements-base.txt
west init -l nrf
west update mcuboot zephyr
- name: Compile new requirements-fixed.txt
working-directory: ncs/nrf/scripts
run: ./compile-requirements.sh ./requirements-fixed.txt

- name: 'Upload Artifact: requirements-fixed.txt'
uses: actions/upload-artifact@v3
with:
name: requirements-fixed
path: ncs/nrf/scripts/requirements-fixed.txt

- name: Push `requirements-fixed.txt` to PR branch if changed
working-directory: ncs/nrf
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.email "[email protected]"
git config user.name "NordicBuilder"
git add scripts/requirements-fixed.txt
git diff --cached HEAD \
--exit-code \
--ignore-space-change \
--ignore-all-space \
--ignore-blank-lines \
--ignore-cr-at-eol \
--ignore-space-at-eol \
&& true
# `git diff` returns 0 if identical
if [ $? != 0 ]; then
echo -e '`requirements-fixed.txt` has changed. Pushing to PR branch.' >> $GITHUB_STEP_SUMMARY
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
else
echo -e 'No changes to `requirements-fixed.txt` needed.' >> $GITHUB_STEP_SUMMARY
fi

0 comments on commit 421d585

Please sign in to comment.