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: Testing pip-requirements workflow #190

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
96 changes: 96 additions & 0 deletions .github/workflows/pip-requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Compile pip requirements and push to PR branch

on:
pull_request_target:
paths:
- 'scripts/requirements-ci.txt'
# types: [opened, synchronize, reopened, ready_for_review, edited]
# - '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
# uses: actions/checkout@v4
# with:
# token: ${{ secrets.NCS_GITHUB_TOKEN }}
# repository: {{ github.repository }}
# ref: {{ github.head_ref }}}
# path: ncs/nrf
# fetch-depth: 1

- name: Checkout PR
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 > date.txt

- name: Commit and push changes
working-directory: ncs/nrf
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.email "[email protected]"
git config user.name "NordicBuilder"
git commit -asm "Updating scripts/requirements-fixed.txt with new fixed versions" -m 'This is an automated commit from github workflow by NordicBuilder'
git push


# - 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: Generate new requirements-fixed.txt
# working-directory: ncs
# run: nrf/scripts/compile-requirements.sh 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 -y $NEW $OLD) || true # Add || true to avoid step failure
# if [[ -n "$DIFF_OUTPUT" ]]; then
# echo "Differences found! Making autocommit"
# echo "difference=true" >> $GITHUB_OUTPUT
# echo '${{ steps.diff.outputs.difference }}'
# else
# echo "No differences found."
# echo "difference=false" >> $GITHUB_OUTPUT
# fi

# - name: Commit and push changes
# if: ${{ steps.diff.outputs.difference == 'true' }}
30 changes: 22 additions & 8 deletions scripts/compile-requirements.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#!/usr/bin/env bash

# This script merges the py-reqs from mcuboot, zephyr, and nrf.

OUT_FILE=$1
[ -z "$OUT_FILE" ] && echo "Error output file not provided" && exit 1
# Check if an argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <path for output file>"
exit 1
fi

# Store the path provided as the first argument
OUT_FILE="$1"

# Check if the path is absolute or relative
if [[ "$OUT_FILE" == /* ]]; then
echo "Absolute path provided: $OUT_FILE"
else
echo "Relative path provided: $PWD/$OUT_FILE"
OUT_FILE="$PWD/$OUT_FILE"
fi
echo "Writing frozen requirements to: $OUT_FILE"
echo "Log python version: $(python --version)"

Expand All @@ -20,13 +32,15 @@ workon pip-fixed-venv > /dev/null 2>&1
pip3 install pip-tools > /dev/null 2>&1
pip3 install setuptools --upgrade


pip-compile --allow-unsafe --output-file $OUT_FILE --strip-extras \
./bootloader/mcuboot/scripts/requirements.txt \
./zephyr/scripts/requirements.txt \
pip-compile --allow-unsafe --build-isolation --strip-extras \
--output-file $OUT_FILE \
--build-isolation \
--annotation-style line \
./nrf/scripts/requirements.txt \
./nrf/scripts/requirements-ci.txt \
./nrf/scripts/requirements-extra.txt
# ./bootloader/mcuboot/scripts/requirements.txt \
# ./zephyr/scripts/requirements.txt \
sed '/^$/d' -i $OUT_FILE
deactivate
rmvirtualenv pip-fixed-venv