ci: check if packages use an APK compatible version
authorPaul Spooren <[email protected]>
Thu, 15 Aug 2024 09:23:59 +0000 (11:23 +0200)
committerPaul Spooren <[email protected]>
Thu, 15 Aug 2024 11:28:12 +0000 (13:28 +0200)
APK uses a deterministic version schema, have the CI check that changed
packages actually follow that version schema.

Signed-off-by: Paul Spooren <[email protected]>
.github/workflows/check-apk-valid-version.yml [new file with mode: 0644]

diff --git a/.github/workflows/check-apk-valid-version.yml b/.github/workflows/check-apk-valid-version.yml
new file mode 100644 (file)
index 0000000..2578046
--- /dev/null
@@ -0,0 +1,103 @@
+name: Check APK compatible version/release
+
+on:
+  pull_request_target:
+    types: [opened, synchronize, converted_to_draft, ready_for_review, edited]
+
+jobs:
+  build:
+    name: Check autorelease deprecation
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+
+    permissions:
+      pull-requests: write
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+          fetch-depth: 0
+
+      - name: Determine branch name
+        run: |
+          BRANCH="${GITHUB_BASE_REF#refs/heads/}"
+          echo "Building for $BRANCH"
+          echo "BRANCH=$BRANCH" >> $GITHUB_ENV
+
+      - name: Setup APK
+        run: |
+          wget -O $GITHUB_WORKSPACE/apk https://buildbot.aparcar.org/apk.static
+          chmod +x $GITHUB_WORKSPACE/apk
+
+      - name: Determine changed packages
+        run: |
+          RET=0
+          INCOMPATIBLE_VERSION=""
+
+          # only detect packages with changes
+          PKG_ROOTS=$(find . -name Makefile | \
+            grep -v ".*/src/Makefile" | \
+            sed -e 's@./\(.*\)/Makefile@\1/@')
+          CHANGES=$(git diff --diff-filter=d --name-only origin/$BRANCH...)
+
+          for ROOT in $PKG_ROOTS; do
+            for CHANGE in $CHANGES; do
+              if [[ "$CHANGE" == "$ROOT"* ]]; then
+                PKG_RELEASE=$(grep -E '^PKG_RELEASE' "$ROOT/Makefile" | cut -f 2 -d '=')
+                if [ -n "$PKG_RELEASE" ]; then
+                  if [[ "$PKG_RELEASE" == '^[0-9]+$' ]]; then
+                    INCOMPATIBLE_VERSION+="$ROOT"
+                    break
+                  fi
+                fi
+                PKG_VERSION=$(grep -E '^PKG_VERSION' "$ROOT/Makefile" | cut -f 2 -d '=')
+                if [ -n "$PKG_VERSION" ]; then
+                  if $GITHUB_WORKSPACE/apk version --check "$PKG_VERSION"; then
+                    INCOMPATIBLE_VERSION+="$ROOT"
+                  fi
+                fi
+              fi
+            done
+          done
+
+          echo "Incompatible versions: $INCOMPATIBLE_VERSION"
+
+          if [ -n "$INCOMPATIBLE_VERSION" ]; then
+            RET=1
+            cat > "$GITHUB_WORKSPACE/pr_comment.md" << EOF
+          OpenWrt will change to the APK package manager which requires
+          deterministic verisons. Please make sure that **PKG_VERSION**
+          follows [Semantic Versioning](https://semver.org) or more specifically,
+          the [APK version scheme](https://gitlab.alpinelinux.org/alpine/apk-tools/-/blob/master/doc/apk-package.5.scd?ref_type=heads#L47).
+          If the version is based on a date, please use dots instead of dashes, i.e. **24.01.01**.
+
+          The **PKG_RELEASE** should be an integer and not contain any letters or special characters.
+
+          EOF
+
+          fi
+
+          for ROOT in $INCOMPATIBLE_VERSION; do
+            echo "  - ${ROOT}Makefile" >> "$GITHUB_WORKSPACE/pr_comment.md"
+          done
+
+          exit $RET
+
+      - name: Find Comment
+        uses: peter-evans/find-comment@v2
+        if: ${{ failure() }}
+        id: fc
+        with:
+          issue-number: ${{ github.event.pull_request.number }}
+          comment-author: "github-actions[bot]"
+
+      - name: Create or update comment
+        uses: peter-evans/create-or-update-comment@v2
+        if: ${{ failure() }}
+        with:
+          comment-id: ${{ steps.fc.outputs.comment-id }}
+          issue-number: ${{ github.event.pull_request.number }}
+          body-file: "pr_comment.md"
+          edit-mode: replace