Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
46 changes: 42 additions & 4 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,45 @@ on:

jobs:

check-pr-exists:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
has_pr: ${{ steps.check.outputs.has_pr }}
steps:
- name: Проверка наличия pull request для ветки
id: check
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
REPOSITORY: ${{ github.repository }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -e
# При push в ветку, для которой уже открыт pull request, контроль
# качества будет выполнен в рамках события pull_request, поэтому
# повторный запуск для события push пропускается во избежание
# дублирования прогонов.
if [ "$EVENT_NAME" == "push" ] \
&& [ "$REF_NAME" != "$DEFAULT_BRANCH" ] \
&& [ "$REF_NAME" != "main" ] \
&& [ "$REF_NAME" != "master" ] \
&& [ "$REF_NAME" != "develop" ]; then
prs=$(gh pr list --repo "$REPOSITORY" --head "$REF_NAME" --state open --json number --jq 'length')
if [ "$prs" -gt 0 ]; then
echo "has_pr=true" >> "$GITHUB_OUTPUT"
else
echo "has_pr=false" >> "$GITHUB_OUTPUT"
fi
else
echo "has_pr=false" >> "$GITHUB_OUTPUT"
fi

test:
needs: [check-pr-exists]
if: needs.check-pr-exists.outputs.has_pr != 'true'
runs-on: ${{ inputs.os_version }}
env:
LANG: ${{ inputs.locale }}.UTF-8
Expand Down Expand Up @@ -217,8 +255,8 @@ jobs:

sonar:
runs-on: ${{ inputs.os_version }}
needs: [test]
if: ${{ (inputs.sonarqube == true) && (github.repository == inputs.github_repository) && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name) }}
needs: [check-pr-exists, test]
if: ${{ (needs.check-pr-exists.outputs.has_pr != 'true') && (inputs.sonarqube == true) && (github.repository == inputs.github_repository) && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name) }}
steps:
- name: Актуализация
uses: actions/checkout@v6.0.2
Expand Down Expand Up @@ -267,8 +305,8 @@ jobs:

coveralls:
runs-on: ${{ inputs.os_version }}
if: inputs.coveralls == true
needs: [test]
if: ${{ (needs.check-pr-exists.outputs.has_pr != 'true') && (inputs.coveralls == true) }}
needs: [check-pr-exists, test]
steps:
- name: Актуализация
uses: actions/checkout@v6.0.2
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,44 @@ on:
default: false

jobs:
check-pr-exists:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
has_pr: ${{ steps.check.outputs.has_pr }}
steps:
- name: Проверка наличия pull request для ветки
id: check
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
REPOSITORY: ${{ github.repository }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -e
# При push в ветку, для которой уже открыт pull request, тесты будут
# запущены в рамках события pull_request, поэтому повторный запуск
# для события push пропускается во избежание дублирования прогонов.
if [ "$EVENT_NAME" == "push" ] \
&& [ "$REF_NAME" != "$DEFAULT_BRANCH" ] \
&& [ "$REF_NAME" != "main" ] \
&& [ "$REF_NAME" != "master" ] \
&& [ "$REF_NAME" != "develop" ]; then
prs=$(gh pr list --repo "$REPOSITORY" --head "$REF_NAME" --state open --json number --jq 'length')
if [ "$prs" -gt 0 ]; then
echo "has_pr=true" >> "$GITHUB_OUTPUT"
else
echo "has_pr=false" >> "$GITHUB_OUTPUT"
fi
else
echo "has_pr=false" >> "$GITHUB_OUTPUT"
fi

build:
needs: [check-pr-exists]
if: needs.check-pr-exists.outputs.has_pr != 'true'
runs-on: ${{ matrix.os }}
env:
LANG: ${{ inputs.locale }}.UTF-8
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ lib.system=../oscript_modules

Сборочная линия для выполнения тестирования библиотеки. Позволяет запустить матричную сборку на настраиваемом списке операционных систем (по умолчанию Windows, Ubuntu и macOS) на нескольких версиях движка OneScript. Поддерживается запуск из ветки, из pull request и ручной запуск из информации о конкретном workflow.

> [!NOTE]
> Чтобы избежать двойного прогона, при событии `push` в ветку, для которой уже открыт pull request, тестирование пропускается — оно будет выполнено в рамках события `pull_request`. Для ветки по умолчанию (а также `main`, `master` и `develop`) тестирование выполняется всегда.

Файл workflow: [https://github.com/autumn-library/workflows/blob/main/.github/workflows/test.yml](https://github.com/autumn-library/workflows/blob/main/.github/workflows/test.yml)

Общие параметры:
Expand Down Expand Up @@ -208,6 +211,9 @@ jobs:
Поддерживается запуск из ветки, из pull request и ручной запуск из информации о конкретном workflow.
> Анализ pull request из форков для задачи SonarQube пока не поддерживается.

> [!NOTE]
> Чтобы избежать двойного прогона, при событии `push` в ветку, для которой уже открыт pull request, контроль качества пропускается — он будет выполнен в рамках события `pull_request`. Для ветки по умолчанию (а также `main`, `master` и `develop`) контроль качества выполняется всегда.

Файл workflow: [https://github.com/autumn-library/workflows/blob/main/.github/workflows/sonar.yml](https://github.com/autumn-library/workflows/blob/main/.github/workflows/sonar.yml)

Параметры:
Expand Down