Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNM: WIP: Adding auto-commit stage to compile-pip-reqs.yml workflow #192

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading