Repository navigation
156 lines (142 loc) · 6.41 KB
/
Copy pathvalidate.yml
File metadata and controls
156 lines (142 loc) · 6.41 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Validate configuration
on:
pull_request:
types: [opened, synchronize, reopened, edited]
push:
branches: [main]
permissions:
contents: read
jobs:
hosted-validation:
name: hosted-validation
# Convenience only. Required-check and host policy need separate migration.
if: ${{ vars.CI_FLEET_HOSTED_VALIDATION == 'true' && (github.event_name != 'pull_request' || github.event.pull_request.state == 'open') && (github.event.action != 'edited' || github.event.changes.base) }}
concurrency:
group: config-validation-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Require independently pinned validator
env:
VALIDATOR: ${{ vars.CI_FLEET_VALIDATOR_REVISION }}
SUITE: ${{ vars.CI_FLEET_SUITE_REVISION }}
run: |
[[ "$VALIDATOR" =~ ^[0-9a-f]{40}$ && "$VALIDATOR" != 0000000000000000000000000000000000000000 ]]
[[ "$SUITE" =~ ^[0-9a-f]{40}$ && "$SUITE" != 0000000000000000000000000000000000000000 ]]
- name: Check out exact source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha || github.sha }}
path: candidate
- name: Check out trusted engine
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: RandomDevelopment/ci-fleet
ref: ${{ vars.CI_FLEET_VALIDATOR_REVISION }}
path: .ci-fleet-validator
persist-credentials: false
fetch-depth: 1
- name: Check out trusted suite
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: RandomDevelopment/ci-fleet-config-template
ref: ${{ vars.CI_FLEET_SUITE_REVISION }}
path: .ci-fleet-suite
persist-credentials: false
fetch-depth: 1
- name: Check out trusted executor
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: RandomDevelopment/ci-fleet
ref: c51844cf05f7a9f647322f4b7cbbb6379f40ad5d
path: .ci-fleet-executor
persist-credentials: false
fetch-depth: 1
- name: Fetch selected histories
env:
GH_TOKEN: ${{ github.token }}
SOURCE: ${{ github.event.pull_request.head.sha || github.sha }}
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
VALIDATOR: ${{ vars.CI_FLEET_VALIDATOR_REVISION }}
SUITE: ${{ vars.CI_FLEET_SUITE_REVISION }}
run: |
fetch_history() {
depth_args=()
if [[ "$(git -C "$1" rev-parse --is-shallow-repository)" == true ]]; then
depth_args+=(--unshallow)
fi
git -C "$1" -c credential.helper= -c 'credential.helper=!gh auth git-credential' \
fetch --no-tags "${depth_args[@]}" origin "${@:2}"
test "$(git -C "$1" rev-parse --is-shallow-repository)" = false
}
source_refs=("$SOURCE")
if [[ -n "$BASE" && "$BASE" != 0000000000000000000000000000000000000000 ]]; then
source_refs+=("$BASE")
fi
fetch_history candidate "${source_refs[@]}"
fetch_history .ci-fleet-validator "$VALIDATOR"
fetch_history .ci-fleet-suite "$SUITE"
- name: Install validation tools
run: |
if ! command -v shellcheck >/dev/null; then
sudo apt-get update
sudo apt-get install -y shellcheck
fi
sudo python3 -I "$GITHUB_WORKSPACE/.ci-fleet-executor/scripts/local_validation_executor.py" --prepare --disposable-host
- name: Run complete local validation
env:
SOURCE: ${{ github.event.pull_request.head.sha || github.sha }}
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
REPOSITORY: ${{ github.repository }}
VALIDATOR: ${{ vars.CI_FLEET_VALIDATOR_REVISION }}
EVENT_NAME: ${{ github.event_name }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
BASE="${BASE:-0000000000000000000000000000000000000000}"
main="$SOURCE"
title_args=()
if [[ "$EVENT_NAME" == "pull_request" ]]; then
main="$BASE"
title_args+=(--pr-title "$PR_TITLE")
fi
sudo python3 -I "$GITHUB_WORKSPACE/.ci-fleet-suite/scripts/local_validate.py" \
--repository "$GITHUB_WORKSPACE/candidate" --repository-name "$REPOSITORY" \
--source "$SOURCE" --base "$BASE" --main "$main" \
--policy-repository "$GITHUB_WORKSPACE/.ci-fleet-validator" --policy "$VALIDATOR" \
--output "$RUNNER_TEMP/local-validation" "${title_args[@]}"
- name: Show validation report
if: always()
run: |
if sudo test -f "$RUNNER_TEMP/local-validation/result.json"; then
sudo cat "$RUNNER_TEMP/local-validation/result.json"
fi
title-validation:
name: hosted-title-validation
if: ${{ vars.CI_FLEET_HOSTED_VALIDATION == 'true' && github.event_name == 'pull_request' && github.event.pull_request.state == 'open' && github.event.action == 'edited' && github.event.changes.title && !github.event.changes.base }}
runs-on: ubuntu-latest
timeout-minutes: 5
concurrency:
group: config-title-validation-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- name: Require independently pinned title validator
env:
VALIDATOR: ${{ vars.CI_FLEET_VALIDATOR_REVISION }}
run: |
[[ "$VALIDATOR" =~ ^[0-9a-f]{40}$ && "$VALIDATOR" != 0000000000000000000000000000000000000000 ]]
- name: Check out trusted title validator
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: RandomDevelopment/ci-fleet
ref: ${{ vars.CI_FLEET_VALIDATOR_REVISION }}
path: .ci-fleet-validator
persist-credentials: false
fetch-depth: 1
- name: Validate edited PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
python3 -I "$GITHUB_WORKSPACE/.ci-fleet-validator/scripts/validate_commits.py" --pr-title "$PR_TITLE"