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 21, 2023
1 parent debc5a9 commit 409df42
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/compile-pip-reqs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Compile requirements-fixed.txt and push to PR

on:
pull_request_target:
paths:
- 'scripts/requirements-ci.txt'
- 'scripts/requirements.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 "Differences found! Pushing changes to PR branch."
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
fi

0 comments on commit 409df42

Please sign in to comment.