mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-02 17:53:30 +00:00
* [AAE-32905] - Improve ADF workflow * [ci:force] * [AAE-32905] - Improve cache use * [AAE-32905] - Improve cache use * [AAE-32905] - Improved workflows * [AAE-32905] - Checking cache * [AAE-32905] - Checking cache * [AAE-32905] - Fix cli * [AAE-32905] - Fix cache * [AAE-32905] - Fix cache * [AAE-32905] - Fix cache * [AAE-32905] - improving workflow and adding some storybook tests * [AAE-32905] - improving workflow and adding some storybook tests * [AAE-32905] - Added more improvements * [AAE-32905] - Added more improvements * [AAE-32905] - bugfix * [AAE-32905] - Added missing part to the cache * [AAE-32905] - bugfix * [AAE-32905] - fixed cache poisoning * [AAE-32905] - timing jobs * [AAE-32905] - chosen to build all together as it's more efficient * [AAE-32905] - Fixed script injection issue
328 lines
11 KiB
YAML
328 lines
11 KiB
YAML
name: "pull-request"
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
dry-run-flag:
|
|
description: "enable dry-run on artifact push"
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
devel:
|
|
description: "devel"
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
cron-run:
|
|
description: "disables jobs which should not run when cron runs e2es"
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
branches:
|
|
- develop
|
|
- master
|
|
- develop-patch*
|
|
- master-patch*
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
GH_COMMIT: ${{ github.sha }}
|
|
NODE_OPTIONS: "--max-old-space-size=5120"
|
|
|
|
jobs:
|
|
pre-checks:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
code-changed: ${{ steps.path-filter.outputs.code-changed }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
|
|
- name: Ensure SHA pinned actions
|
|
uses: hyland/github-actions-ensure-sha-pinned-actions@7d494b6b53e71f75194d74b4dd890a2266d060b5 # v2.0.0
|
|
|
|
- name: Check package-lock.json version
|
|
run: |
|
|
if [[ $(jq '.lockfileVersion == 3' package-lock.json) == "true" ]] ; then
|
|
echo "package-lock.json has a correct version"
|
|
else
|
|
echo "package-lock must be version 3"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Detect code changes
|
|
id: path-filter
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
if [ "${{ github.event_name }}" != "pull_request" ]; then
|
|
echo "Not a PR event — assuming code changed"
|
|
echo "code-changed=true" >> $GITHUB_OUTPUT
|
|
exit 0
|
|
fi
|
|
|
|
FILES=$(gh api /repos/$GITHUB_REPOSITORY/pulls/${{ github.event.pull_request.number }}/files --paginate --jq '.[].filename')
|
|
|
|
CODE_CHANGED="false"
|
|
while IFS= read -r file; do
|
|
case "$file" in
|
|
*.md|docs/*|.github/*.md|.github/CODEOWNERS|.github/dependabot.yml|LICENSE*|NOTICE*|.editorconfig|.gitattributes)
|
|
;;
|
|
*)
|
|
CODE_CHANGED="true"
|
|
break
|
|
;;
|
|
esac
|
|
done <<< "$FILES"
|
|
|
|
echo "code-changed=$CODE_CHANGED" >> $GITHUB_OUTPUT
|
|
echo "Code changed: $CODE_CHANGED"
|
|
|
|
check-if-pr-is-approved:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check if PR approval can be skipped
|
|
id: skip-check
|
|
env:
|
|
EVENT_NAME: ${{ github.event_name }}
|
|
ACTOR: ${{ github.actor }}
|
|
DEVEL_FLAG: ${{ inputs.devel }}
|
|
COMMIT_MESSAGE: ${{ github.event.head_commit.message || github.event.pull_request.title || '' }}
|
|
run: |
|
|
skip="false"
|
|
|
|
if [ "$EVENT_NAME" == "schedule" ] || [ "$EVENT_NAME" == "workflow_dispatch" ]; then
|
|
echo -e "\033[32mSchedule/dispatch event — skipping approval check\033[0m"
|
|
skip="true"
|
|
elif [ "$ACTOR" == "dependabot[bot]" ] || [ "$ACTOR" == "alfresco-build" ]; then
|
|
echo -e "\033[32mCommit by $ACTOR — skipping approval check\033[0m"
|
|
skip="true"
|
|
elif [[ "$COMMIT_MESSAGE" == *"[ci:force]"* ]]; then
|
|
echo -e "\033[32m[ci:force] flag detected — skipping approval check\033[0m"
|
|
skip="true"
|
|
elif [[ "$DEVEL_FLAG" == "true" ]]; then
|
|
echo -e "\033[32mDevel flag — skipping approval check\033[0m"
|
|
skip="true"
|
|
fi
|
|
|
|
echo "skip=$skip" >> $GITHUB_OUTPUT
|
|
|
|
- name: Get PR number
|
|
if: ${{ steps.skip-check.outputs.skip != 'true' }}
|
|
id: pr-number
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
PR_NUMBER="${{ github.event.pull_request.number }}"
|
|
if [ -z "$PR_NUMBER" ]; then
|
|
PR_NUMBER=$(gh pr view --json number --jq '.number' 2>/dev/null || echo "")
|
|
fi
|
|
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
|
|
echo "PR: $PR_NUMBER"
|
|
|
|
- name: Check if PR is approved
|
|
if: ${{ steps.skip-check.outputs.skip != 'true' && steps.pr-number.outputs.pr_number != '' }}
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
PR_NUMBER: ${{ steps.pr-number.outputs.pr_number }}
|
|
run: |
|
|
echo "Checking approval for PR: $PR_NUMBER"
|
|
checkApproval=$(gh api /repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/reviews | jq '.[] | select(.state == "APPROVED") | .user.login')
|
|
if [[ $checkApproval ]]; then
|
|
echo -e "\033[32mPR approved\033[0m"
|
|
else
|
|
echo -e "\033[31mPR NOT approved\033[0m"
|
|
exit 1
|
|
fi
|
|
|
|
setup:
|
|
timeout-minutes: 30
|
|
name: "Setup"
|
|
runs-on: ubuntu-latest
|
|
needs: [check-if-pr-is-approved, pre-checks]
|
|
if: ${{ needs.pre-checks.outputs.code-changed == 'true' }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Setup environment
|
|
id: setup-env
|
|
uses: ./.github/actions/setup
|
|
with:
|
|
cache-suffix: setup
|
|
- name: Install dependencies
|
|
if: ${{ steps.setup-env.outputs.node-modules-cache-hit != 'true' }}
|
|
run: npm ci
|
|
- name: Bundle
|
|
run: |
|
|
npm run bundle:js-api
|
|
npm run bundle:cli
|
|
- name: Save nx cache
|
|
if: ${{ success() }}
|
|
uses: ./.github/actions/save-nx-cache
|
|
with:
|
|
cache-suffix: setup
|
|
|
|
lint:
|
|
timeout-minutes: 30
|
|
name: "Lint"
|
|
runs-on: ubuntu-latest
|
|
needs: [setup]
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Setup environment
|
|
id: setup-env
|
|
uses: ./.github/actions/setup
|
|
with:
|
|
cache-suffix: lint
|
|
full-setup: 'false'
|
|
- name: Install dependencies
|
|
if: ${{ steps.setup-env.outputs.node-modules-cache-hit != 'true' }}
|
|
run: npm ci
|
|
- name: Run lint
|
|
env:
|
|
BASE_REF: ${{ github.base_ref || 'develop' }}
|
|
run: npx nx affected --target=lint --base=origin/$BASE_REF --head=HEAD
|
|
- name: Save nx cache
|
|
if: ${{ success() }}
|
|
uses: ./.github/actions/save-nx-cache
|
|
with:
|
|
cache-suffix: lint
|
|
|
|
trigger-build:
|
|
name: "Build Libs"
|
|
needs: [setup]
|
|
uses: ./.github/workflows/build-lib-workflow.yml
|
|
with:
|
|
base_ref: ${{ github.base_ref || 'develop' }}
|
|
|
|
build-storybook:
|
|
timeout-minutes: 30
|
|
name: "Build Storybook"
|
|
needs: [setup]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Setup environment
|
|
id: setup-env
|
|
uses: ./.github/actions/setup
|
|
with:
|
|
cache-suffix: storybook
|
|
full-setup: 'false'
|
|
- name: Install dependencies
|
|
if: ${{ steps.setup-env.outputs.node-modules-cache-hit != 'true' }}
|
|
run: npm ci
|
|
- name: Build Storybook
|
|
env:
|
|
BASE_REF: ${{ github.base_ref || 'develop' }}
|
|
run: |
|
|
npx nx affected --target=build-storybook --base=origin/$BASE_REF --head=HEAD --configuration=ci
|
|
- name: Save nx cache
|
|
if: ${{ success() }}
|
|
uses: ./.github/actions/save-nx-cache
|
|
with:
|
|
cache-suffix: storybook
|
|
|
|
trigger-unit-tests:
|
|
name: "Unit Tests"
|
|
needs: [setup]
|
|
uses: ./.github/workflows/unit-test-workflow.yml
|
|
with:
|
|
base_ref: ${{ github.base_ref || 'develop' }}
|
|
|
|
PR-size-check:
|
|
if: ${{ github.event_name == 'pull_request' }}
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check PR size
|
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
|
with:
|
|
script: |
|
|
const { data: pr } = await github.rest.pulls.get({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: context.issue.number,
|
|
});
|
|
|
|
const additions = pr.additions;
|
|
const deletions = pr.deletions;
|
|
const totalChanges = additions + deletions;
|
|
const changedFiles = pr.changed_files;
|
|
|
|
let size = 'S';
|
|
if (totalChanges > 1000 || changedFiles > 30) size = 'XL';
|
|
else if (totalChanges > 500 || changedFiles > 20) size = 'L';
|
|
else if (totalChanges > 200 || changedFiles > 10) size = 'M';
|
|
|
|
core.summary
|
|
.addHeading('PR Size: ' + size, 3)
|
|
.addTable([
|
|
[{data: 'Metric', header: true}, {data: 'Count', header: true}],
|
|
['Files changed', String(changedFiles)],
|
|
['Additions', '+' + String(additions)],
|
|
['Deletions', '-' + String(deletions)],
|
|
['Total changes', String(totalChanges)],
|
|
]);
|
|
|
|
if (size === 'XL') {
|
|
core.summary.addRaw('⚠️ This PR is very large. Consider splitting it into smaller PRs for easier review.');
|
|
}
|
|
|
|
await core.summary.write();
|
|
|
|
if (size === 'XL') {
|
|
core.warning('This PR has ' + totalChanges + ' changes across ' + changedFiles + ' files. Consider splitting it for easier review.');
|
|
}
|
|
|
|
PR-forbidden-labels:
|
|
if: ${{ inputs.cron-run == '' || inputs.cron-run == 'false' }}
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check for forbidden labels
|
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
|
with:
|
|
script: |
|
|
const { data: issue } = await github.rest.issues.get({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.issue.number,
|
|
});
|
|
const labels = issue.labels?.map(item => item.name) || [];
|
|
const forbidden = ['next version ➡️', 'do not merge🙅🏻♂️'];
|
|
|
|
if (forbidden.some(l => labels.includes(l))) {
|
|
core.setFailed('The PR contains a forbidden label! You are not allowed to merge until the label is there.');
|
|
}
|
|
|
|
finalize:
|
|
if: ${{ always() }}
|
|
runs-on: ubuntu-latest
|
|
name: Final Results
|
|
needs:
|
|
[
|
|
check-if-pr-is-approved,
|
|
pre-checks,
|
|
setup,
|
|
trigger-unit-tests,
|
|
lint,
|
|
trigger-build,
|
|
build-storybook,
|
|
PR-forbidden-labels,
|
|
]
|
|
steps:
|
|
- name: Check job execution status
|
|
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
|
|
run: exit 1
|