Repository navigation
145 lines (131 loc) · 6.18 KB
/
Copy pathbuild-dev.yml
File metadata and controls
145 lines (131 loc) · 6.18 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
name: Build PR
on:
pull_request:
types: [synchronize]
workflow_dispatch:
inputs:
docker_tag:
description: "Docker Tag Prefix (leave blank for no docker build)"
required: false
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
prinfo:
name: "Get PR info"
runs-on: ubuntu-latest
outputs:
run_builds: ${{ steps.loadinfo.outputs.run_builds }}
build_docker: ${{ steps.loadinfo.outputs.build_docker }}
docker_tag: ${{ steps.loadinfo.outputs.docker_tag }}
# commit_ref = the EXACT PR head sha (raw git SHA, NOT slash-normalized like docker_tag).
# Passed to the build workflow so it builds the real branch code and NOT the auto-generated
# PR/base merge commit. DO NOT REMOVE.
commit_ref: ${{ steps.loadinfo.outputs.commit_ref }}
steps:
- name: "Load PR info"
id: loadinfo
env:
HAS_DOCKER_IMAGE_LABEL: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'build-docker-image') }}
SAME_REPOSITORY_PR: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
MANUAL_DOCKER_TAG: ${{ inputs.docker_tag }}
PR_NUMBER: ${{ github.event.pull_request.number }}
# PR head sha (exact branch HEAD). Read via env to avoid script injection. DO NOT REMOVE.
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
FALLBACK_SHA: ${{ github.sha }}
run: |
has_docker_image_label="$HAS_DOCKER_IMAGE_LABEL"
same_repository_pr="$SAME_REPOSITORY_PR"
run_builds="$has_docker_image_label"
build_docker="false"
echo "docker image label: $has_docker_image_label"
echo "same repository PR: $same_repository_pr"
branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
echo "branch name: $branch_name"
# Build the EXACT pushed commit. On a `pull_request` event, actions/checkout with no
# ref defaults to refs/pull/<N>/merge (branch MERGED with the base) — wrong for diverged
# branches. Pinning head.sha avoids that. DO NOT REMOVE — see _shared-build.yaml `ref`.
commit_ref="$HEAD_SHA"
if [[ -z "$commit_ref" ]]; then
commit_ref="$FALLBACK_SHA"
fi
echo "commit ref: $commit_ref"
manual_tag="$MANUAL_DOCKER_TAG"
if [[ ! -z "$manual_tag" ]]; then
# Manual tags must be valid docker tags and must not take reserved names
# (master/main/latest/pr and their -suffixed tags, or release tags).
if [[ ! "$manual_tag" =~ ^[A-Za-z0-9_][A-Za-z0-9_.-]{0,100}$ || "$manual_tag" =~ ^(master|main|latest|pr)(-|$)|^v[0-9] ]]; then
echo "::error::reserved or invalid docker tag: use letters, digits, _ . - (write / as -), and no master, main, latest or pr prefix or v<digit> start"
exit 1
fi
branch_name="$manual_tag"
run_builds="true"
build_docker="true"
elif [[ "$has_docker_image_label" == "true" ]] && [[ "$same_repository_pr" == "true" ]]; then
build_docker="true"
elif [[ "$has_docker_image_label" == "true" ]]; then
echo "Skipping docker push for forked PR; dispatch this workflow manually to publish a trusted build."
fi
# PR builds are tagged with the branch name (/ becomes -). A name that isn't a
# valid tag, or would take a reserved one (master, main, latest, pr, releases),
# is tagged pr-<number> instead.
if [[ -n "$PR_NUMBER" ]]; then
branch_name="${branch_name//\//-}"
if [[ ! "$branch_name" =~ ^[A-Za-z0-9_][A-Za-z0-9_.-]{0,100}$ || "$branch_name" =~ ^(master|main|latest|pr)(-|$)|^v?[0-9] ]]; then
branch_name="pr-$PR_NUMBER"
fi
echo "docker tag: $branch_name"
fi
if [[ "$branch_name" == "master" ]] || [[ "$branch_name" =~ ^v[0-9] ]]; then
echo "Invalid branch name! Skipping builds"
run_builds="false"
build_docker="false"
fi
echo "run_builds=$run_builds" >> $GITHUB_OUTPUT
echo "build_docker=$build_docker" >> $GITHUB_OUTPUT
docker_tag="${branch_name//\//-}"
echo "docker_tag=$docker_tag" >> $GITHUB_OUTPUT
echo "commit_ref=$commit_ref" >> $GITHUB_OUTPUT
check_source:
name: "Run code checks"
needs: [prinfo]
if: ${{ needs.prinfo.outputs.run_builds == 'true' }}
uses: ./.github/workflows/_shared-check.yaml
build_binaries:
name: "Build Assertoor"
needs: [prinfo, check_source]
if: ${{ needs.prinfo.outputs.run_builds == 'true' && needs.prinfo.outputs.build_docker != 'true' }}
# Needed to call _shared-build.yaml at all: GitHub checks its docker jobs'
# permissions against this job's even when they are skipped.
permissions:
contents: read
packages: write
id-token: write
attestations: write
uses: ./.github/workflows/_shared-build.yaml
with:
ref: ${{ needs.prinfo.outputs.commit_ref }} # exact branch HEAD, NOT the PR/base merge. DO NOT REMOVE.
docker: false
docker_repository: "ghcr.io/ethpandaops/assertoor"
docker_tag_prefix: ${{needs.prinfo.outputs.docker_tag}}
additional_tags: "['${{needs.prinfo.outputs.docker_tag}}','${{needs.prinfo.outputs.docker_tag}}-latest']"
build_binaries_and_docker:
name: "Build Assertoor and Docker image"
needs: [prinfo, check_source]
if: ${{ needs.prinfo.outputs.run_builds == 'true' && needs.prinfo.outputs.build_docker == 'true' }}
permissions:
contents: read
packages: write
id-token: write
attestations: write
uses: ./.github/workflows/_shared-build.yaml
with:
ref: ${{ needs.prinfo.outputs.commit_ref }} # exact branch HEAD, NOT the PR/base merge. DO NOT REMOVE.
docker: true
docker_repository: "ghcr.io/ethpandaops/assertoor"
docker_tag_prefix: ${{needs.prinfo.outputs.docker_tag}}
additional_tags: "['${{needs.prinfo.outputs.docker_tag}}','${{needs.prinfo.outputs.docker_tag}}-latest']"
secrets:
IMAGE_MIRROR_URL: ${{ secrets.IMAGE_MIRROR_URL }}