-
Notifications
You must be signed in to change notification settings - Fork 3
111 lines (95 loc) · 3.72 KB
/
Copy pathcreate-pr-build.yml
File metadata and controls
111 lines (95 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Create PR Build
run-name: "PR Build: #${{ github.event.pull_request.number }} (${{ github.run_attempt }}.${{ github.run_number }}) - ${{ github.event.pull_request.title }}"
on:
pull_request:
branches:
- 'main'
defaults:
run:
shell: bash
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-docs-commit:
runs-on: ubuntu-latest
outputs:
skip-build: ${{ steps.check.outputs.skip-build }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Check if last commit was from docs rebuild bot
id: check
run: |
LAST_AUTHOR=$(git log -1 --format='%an' HEAD^2)
LAST_MESSAGE=$(git log -1 --format='%s' HEAD^2)
echo "Last commit author: $LAST_AUTHOR"
echo "Last commit message: $LAST_MESSAGE"
if [[ "$LAST_AUTHOR" == "howso-automation" && "$LAST_MESSAGE" == "Automated docs rebuild" ]]; then
echo "Last commit was from the docs rebuild bot. Skipping build."
echo "skip-build=true" >> $GITHUB_OUTPUT
else
echo "skip-build=" >> $GITHUB_OUTPUT
fi
set-pr-version:
if: needs.check-docs-commit.outputs.skip-build != 'true'
needs: ["check-docs-commit"]
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-pr-version.outputs.version }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get previous git tag
id: previous-tag
run: |
tag=$(git for-each-ref --sort=-creatordate --count 5 --format="%(refname:short)" "refs/tags/" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+" | head -n 1)
echo "Found tag: $tag"
echo "tag=$(echo $tag)" >> $GITHUB_OUTPUT
- name: Get next patch version from previous tag
id: next-semvers
run: |
IFS='.' read -r major minor patch <<< "${{ steps.previous-tag.outputs.tag }}"
echo "patch=${major}.${minor}.$((patch + 1))" >> $GITHUB_OUTPUT
echo "major=$((major + 1)).0.0" >> $GITHUB_OUTPUT
echo "minor=${major}.$((minor + 1)).0" >> $GITHUB_OUTPUT
- name: Set PR version
id: set-pr-version
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
PR_ITERATION=${{ github.run_attempt }}.${{ github.run_number }}
echo "version=$(echo ${{ steps.next-semvers.outputs.patch }}-alpha+PR.${PR_NUMBER}.${PR_ITERATION})" >> $GITHUB_OUTPUT
build:
if: needs.check-docs-commit.outputs.skip-build != 'true'
needs: ['check-docs-commit', 'set-pr-version']
uses: "./.github/workflows/build.yml"
secrets: inherit
with:
version: ${{ needs.set-pr-version.outputs.version }}
build-type: "PR"
rebuild-docs:
if: needs.check-docs-commit.outputs.skip-build != 'true'
needs: ['check-docs-commit', 'set-pr-version', 'build']
uses: "./.github/workflows/rebuild-docs.yml"
secrets: inherit
with:
version: ${{ needs.set-pr-version.outputs.version }}
# This job is here to have only one final step to add for "Status Checks"
# in GitHub, instead of adding every leaf test from 'build'
final-check:
needs: ["check-docs-commit", "build"]
if: |
always() && (
needs.check-docs-commit.outputs.skip-build == 'true' ||
(contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled'))
)
runs-on: ubuntu-latest
steps:
- name: Skip — docs bot commit detected
if: needs.check-docs-commit.outputs.skip-build == 'true'
run: echo "Last commit was an automated docs rebuild. Skipping build pipeline."
- name: Fail — build or upstream job failed
if: needs.check-docs-commit.outputs.skip-build != 'true'
run: exit 1