From 78af3d804f56f2a51267010dd50cab1dcf46d8b7 Mon Sep 17 00:00:00 2001 From: Thomas Stilwell Date: Thu, 21 Sep 2023 15:05:54 +0200 Subject: [PATCH 1/2] add `compile-pip-reqs.yml` workflow --- .github/workflows/pip-requirements.yml | 96 ++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/pip-requirements.yml diff --git a/.github/workflows/pip-requirements.yml b/.github/workflows/pip-requirements.yml new file mode 100644 index 0000000000..27c3d626d7 --- /dev/null +++ b/.github/workflows/pip-requirements.yml @@ -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 "NordicBuilder@github.com" + 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' }} From 09326f2ef093c778b04388b839f9e67d35d3fea3 Mon Sep 17 00:00:00 2001 From: Thomas Stilwell Date: Thu, 21 Sep 2023 21:23:28 +0200 Subject: [PATCH 2/2] update compile-requriements.txt --- scripts/compile-requirements.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/scripts/compile-requirements.sh b/scripts/compile-requirements.sh index 6bac8bae65..2af6d8e920 100755 --- a/scripts/compile-requirements.sh +++ b/scripts/compile-requirements.sh @@ -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 " + 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)" @@ -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