-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version check when needs review label is added
- Loading branch information
1 parent
b9b2e08
commit 986e67e
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Check PR for Review | ||
|
||
on: | ||
pull_request: | ||
types: [labeled] | ||
|
||
permissions: | ||
contents: read # to fetch code (actions/checkout) | ||
pull-requests: write # to comment on the PR | ||
|
||
jobs: | ||
check-pr: | ||
if: contains(github.event.label.name, 'needs review') && github.event.pull_request.draft == "true" | ||
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: pr-details | ||
run: ./script/version_check.sh ${{ github.event.pull_request.body }} | ||
|
||
- name: Add comment if versions differ | ||
if: steps.version-check.outputs.version_mismatch == 'true' | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: ${{ github.event.pull_request.number }}, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `Version mismatch detected:\n | ||
- Work package URL: ${steps.pr-details.outputs.wp_url}\n | ||
- Work package version: ${steps.pr-details.outputs.wp_version}\n | ||
- Core version: ${steps.pr-details.outputs.core_version}\n` | ||
}) | ||
- name: Output success | ||
if: success() && steps.version-check.outputs.version_mismatch != 'true' | ||
run: echo "Version check passed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/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 "::set-output name=version_mismatch::true" | ||
echo "::set-output name=wp_version::${VERSION_FROM_API}" | ||
echo "::set-output name=wp_url::${WP_URL}" | ||
echo "::set-output name=core_version::${VERSION_FROM_FILE}" | ||
else | ||
echo "Version from the work package ${WORK_PACKAGE_ID} matches the version in the version file this PR targets." | ||
fi |