xref: /freebsd/contrib/libfido2/.actions/build-bsd (revision 60a517b66a69b8c011b04063ef63a938738719bd)
1*60a517b6SEd Maste#!/bin/sh -eux
2*60a517b6SEd Maste
3*60a517b6SEd Maste# Copyright (c) 2022 Yubico AB. All rights reserved.
4*60a517b6SEd Maste# Use of this source code is governed by a BSD-style
5*60a517b6SEd Maste# license that can be found in the LICENSE file.
6*60a517b6SEd Maste# SPDX-License-Identifier: BSD-2-Clause
7*60a517b6SEd Maste
8*60a517b6SEd MasteBASE_URL="https://builds.sr.ht"
9*60a517b6SEd MasteMANIFEST="$(mktemp)"
10*60a517b6SEd MasteLOGFILE="$(mktemp)"
11*60a517b6SEd Mastetrap '[ -f "${LOGFILE}" ] && cat -- "${LOGFILE}"' EXIT
12*60a517b6SEd Maste
13*60a517b6SEd Maste# construct the sourcehut build manifest
14*60a517b6SEd Mastecat > "${MANIFEST}" <<- EOF
15*60a517b6SEd Masteimage: ${IMAGE}
16*60a517b6SEd Mastepackages:
17*60a517b6SEd Maste  - cmake
18*60a517b6SEd Maste  - llvm
19*60a517b6SEd Maste  - pcsc-lite
20*60a517b6SEd MasteEOF
21*60a517b6SEd Maste
22*60a517b6SEd Mastecase "${IMAGE}" in
23*60a517b6SEd Maste	freebsd*)
24*60a517b6SEd Mastecat >> "${MANIFEST}" <<- EOF
25*60a517b6SEd Maste  - libcbor
26*60a517b6SEd Maste  - pkgconf
27*60a517b6SEd MasteEOF
28*60a517b6SEd Maste	;;
29*60a517b6SEd Masteesac
30*60a517b6SEd Maste
31*60a517b6SEd Mastecat >> "${MANIFEST}" <<- EOF
32*60a517b6SEd Mastesources:
33*60a517b6SEd Maste  - ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}#$(git rev-parse HEAD)
34*60a517b6SEd Mastetasks:
35*60a517b6SEd Maste  - build: |
36*60a517b6SEd Maste      if [ "\$(uname)" = "OpenBSD" ]; then
37*60a517b6SEd Maste        SUDO="doas -u root"
38*60a517b6SEd Maste      else
39*60a517b6SEd Maste        SUDO=sudo
40*60a517b6SEd Maste      fi
41*60a517b6SEd Maste      SCAN="/usr/local/bin/scan-build --use-cc=/usr/bin/cc --status-bugs"
42*60a517b6SEd Maste      cd libfido2
43*60a517b6SEd Maste      for T in Debug Release; do
44*60a517b6SEd Maste        mkdir build-\$T
45*60a517b6SEd Maste        (cd build-\$T && \${SCAN} cmake -DCMAKE_BUILD_TYPE=\$T ..)
46*60a517b6SEd Maste        \${SCAN} make -j"\$(sysctl -n hw.ncpu)" -C build-\$T
47*60a517b6SEd Maste        make -C build-\$T regress
48*60a517b6SEd Maste        \${SUDO} make -C build-\$T install
49*60a517b6SEd Maste      done
50*60a517b6SEd MasteEOF
51*60a517b6SEd Maste
52*60a517b6SEd Masteq() {
53*60a517b6SEd Maste	curl \
54*60a517b6SEd Maste		--silent \
55*60a517b6SEd Maste		--oauth2-bearer "${SOURCEHUT_TOKEN}" \
56*60a517b6SEd Maste		--header "Content-Type: application/json" \
57*60a517b6SEd Maste		--data @- -- \
58*60a517b6SEd Maste		"${BASE_URL}/query" \
59*60a517b6SEd Maste	| tee -a -- "${LOGFILE}"
60*60a517b6SEd Maste}
61*60a517b6SEd Maste
62*60a517b6SEd Mastesubmit_job() {
63*60a517b6SEd Maste	local manifest="$1"
64*60a517b6SEd Maste	jq \
65*60a517b6SEd Maste		--compact-output --null-input \
66*60a517b6SEd Maste		'{ query: $body, variables: { var: $var } }' \
67*60a517b6SEd Maste		--arg body 'mutation($var: String!) { submit(manifest: $var) { id } }' \
68*60a517b6SEd Maste		--rawfile var "${manifest}" \
69*60a517b6SEd Maste	| q \
70*60a517b6SEd Maste	| jq --exit-status --raw-output '.data.submit.id'
71*60a517b6SEd Maste}
72*60a517b6SEd Maste
73*60a517b6SEd Mastejob_status() {
74*60a517b6SEd Maste	local id="$1"
75*60a517b6SEd Maste	jq \
76*60a517b6SEd Maste		--compact-output --null-input \
77*60a517b6SEd Maste		'{ query: $body, variables: { var: $var } }' \
78*60a517b6SEd Maste		--arg body 'query($var: Int!) { job(id: $var) { status } }' \
79*60a517b6SEd Maste		--argjson var "${id}" \
80*60a517b6SEd Maste	| q \
81*60a517b6SEd Maste	| jq --exit-status --raw-output '.data.job.status'
82*60a517b6SEd Maste}
83*60a517b6SEd Maste
84*60a517b6SEd MasteJOB_ID="$(submit_job "${MANIFEST}")" || exit 1
85*60a517b6SEd Maste[ -z "${JOB_ID}" ] && exit 1
86*60a517b6SEd Masteecho "Job '${JOB_ID}' running at ${BASE_URL}/~yubico-libfido2/job/${JOB_ID}"
87*60a517b6SEd Maste
88*60a517b6SEd Mastewhile true; do
89*60a517b6SEd Maste	JOB_STATUS="$(job_status "${JOB_ID}")" || exit 1
90*60a517b6SEd Maste	case "${JOB_STATUS}" in
91*60a517b6SEd Maste		SUCCESS) exit 0;;
92*60a517b6SEd Maste		FAILED) exit 1;;
93*60a517b6SEd Maste		PENDING|QUEUED|RUNNING) ;;
94*60a517b6SEd Maste		*) exit 1;;
95*60a517b6SEd Maste	esac
96*60a517b6SEd Maste	sleep 60
97*60a517b6SEd Mastedone
98