Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add version check when needs review label is added

Oliver Güntherb0103d508555
diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml
new file mode 100644
index 00000000000..ae59544f94e
--- /dev/null
+++ b/.github/workflows/version-check.yml
@@ -0,0 +1,47 @@
+name: Check work package version
+
+on:
+ pull_request:
+ types: [labeled, synchronize]
+
+permissions:
+ contents: read # to fetch code (actions/checkout)
+ pull-requests: write # to comment on the PR
+
+jobs:
+ check-pr:
+ if: contains(github.event.pull_request.labels.*.name, 'needs review')
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Set up Ruby
+ uses: ruby/setup-ruby@v1
+
+ - name: Verify linked version matches core version
+ id: version-check
+ run: ./script/ci/version_check.sh ${{ github.event.pull_request.body }}
+
+ - name: Add comment if versions differ
+ if: steps.version-check.outputs.version_mismatch == 'true'
+ uses: marocchino/sticky-pull-request-comment@v2
+ with:
+ header: version-mismatch-comment
+ message: |
+ The provided work package version does not match the core version:
+
+ - Work package URL: ${{ steps.version-check.outputs.wp_url }}
+ - Work package version: ${{steps.version-check.outputs.wp_version}}
+ - Core version: ${{steps.version-check.outputs.core_version}}
+
+ Please make sure that:
+
+ - The work package version OR your pull request target branch is correct
+ - name: Version check passed
+ if: steps.version-check.outputs.version_mismatch != 'true'
+ uses: marocchino/sticky-pull-request-comment@v2
+ with:
+ header: version-mismatch-comment
+ delete: true
diff --git a/script/ci/version_check.sh b/script/ci/version_check.sh
new file mode 100755
index 00000000000..39558a4984f
--- /dev/null
+++ b/script/ci/version_check.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+#-- copyright
+# OpenProject is a project management system.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See doc/COPYRIGHT.rdoc for more details.
+#++
+
+set -e
+
+# script/ci/version_check
+
+PR_BODY="$1"
+
+# Extract URL from PR description
+WP_URL=$(echo "${PR_BODY}" | grep -oE 'https://community.openproject.org/(wp|work_packages|projects/[^/]+/work_packages)/[0-9]+')
+
+if [ -z "$WP_URL" ]; then
+ echo "::warning::PR description does not contain a valid URL to an OpenProject ticket."
+ exit 0
+fi
+
+# Extract the work package ID
+WORK_PACKAGE_ID=$(echo "$WP_URL" | grep -oE '[0-9]+$')
+echo "Work Package ID: $WORK_PACKAGE_ID"
+
+# Perform API request to fetch version
+API_URL="https://community.openproject.org/api/v3/work_packages/${WORK_PACKAGE_ID}"
+RESPONSE=$(curl -s -w "%{http_code}" -o response.json "$API_URL")
+HTTP_STATUS=$(tail -n1 <<< "$RESPONSE")
+
+if [ "$HTTP_STATUS" -ne 200 ]; then
+ echo "API request failed with status code $HTTP_STATUS. Exiting."
+ cat response.json
+ exit 0
+fi
+
+VERSION_FROM_API=$(jq -r '._links.version.title // empty' response.json)
+if [ -z "$VERSION_FROM_API" ]; then
+ echo "::warning::Failed to extract version from API response."
+ exit 0
+fi
+
+echo "Version from API: $VERSION_FROM_API"
+
+# Extract version from the Ruby file using 'rake version'
+VERSION_FROM_FILE=$(ruby -e 'require_relative "./lib/open_project/version"; puts OpenProject::VERSION.to_s')
+
+echo "Version from file: $VERSION_FROM_FILE"
+
+# Compare the versions
+if [[ "$VERSION_FROM_API" != "$VERSION_FROM_FILE" ]]; then
+ echo "Version mismatch detected."
+
+
+ echo "version_mismatch=true" >> $GITHUB_OUTPUT
+ echo "wp_url=${WP_URL}" >> $GITHUB_OUTPUT
+ echo "wp_version=${VERSION_FROM_API}" >> $GITHUB_OUTPUT
+ echo "core_version=${VERSION_FROM_FILE}" >> $GITHUB_OUTPUT
+else
+ echo "Version from the work package ${WORK_PACKAGE_ID} matches the version in the version file this PR targets."
+fi