forked from digitalocean/prometheus-client-c
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump version to 1.2.0 and add github actions for CI and Doc updates.
- Loading branch information
Jens Elkner
committed
Nov 16, 2023
1 parent
242eac1
commit 55c3b8e
Showing
4 changed files
with
376 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,140 @@ | ||
name: CI | ||
# This workflow is triggered on pushes to the repository. | ||
|
||
env: | ||
GHAH: etc/gha-helper.sh | ||
MISSING_BUILD_PKGS: 'ksh libmicrohttpd-dev' | ||
MISSING_DOC_PKGS: 'doxygen graphviz' | ||
PROTO: '/var/tmp/proto' | ||
|
||
on: | ||
- push | ||
- pull_request | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
paths-ignore: | ||
- '.github/**' | ||
- '.gitignore' | ||
- 'example/**' | ||
- 'promtest/**' | ||
- 'vendor/**' | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: pr-build-and-deploy-${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
ubuntu-20-04: | ||
name: ubuntu-20-04 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: test | ||
env: | ||
DOCKER_IMAGE: ubuntu:20.04 | ||
CI: 1 | ||
run: make | ||
ubuntu-18-04: | ||
name: ubuntu-18-04 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: test | ||
env: | ||
DOCKER_IMAGE: ubuntu:18.04 | ||
CI: 1 | ||
run: make | ||
ubuntu-16-04: | ||
name: ubuntu-16-04 | ||
runs-on: ubuntu-latest | ||
job_1a: | ||
name: Build | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: test | ||
- name: Environment | ||
env: | ||
DOCKER_IMAGE: ubuntu:16.04 | ||
CI: 1 | ||
run: make | ||
debian-buster: | ||
name: debian-buster | ||
runs-on: ubuntu-latest | ||
GITHUB_CTX: ${{ toJSON(github) }} | ||
MY_ENV: ${{ toJSON(env) }} | ||
RUNNER_CTX: ${{ toJSON(runner) }} | ||
run: | | ||
lsb_release -a | ||
printf "github:\n$GITHUB_CTX\n" | ||
printf "env:\n$MY_ENV\n" | ||
printf "env:\n$RUNNER_CTX\n" | ||
df -h | ||
mount | ||
echo "DISTRO_NAME=$( lsb_release -is )" >>$GITHUB_ENV | ||
echo "DISTRO_VERSION=$( lsb_release -rs )" >>$GITHUB_ENV | ||
echo "GITHUB_SHA_SHORT=$( echo ${GITHUB_SHA:0:7} )" >>$GITHUB_ENV | ||
- name: Install packages | ||
run: | | ||
echo 'man-db man-db/auto-update boolean false' | \ | ||
sudo debconf-set-selections | ||
sudo rm -f /var/lib/man-db/auto-update | ||
sudo apt-get update | ||
# stupid debian shipped experimental and total broken ksh2020 as ksh | ||
# package and the stable one as ksh93 in focal. | ||
sudo apt-get install ksh93 || sudo apt-get install ksh | ||
sudo apt-get install ${MISSING_BUILD_PKGS} | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Build | ||
run: | | ||
echo "APP_VERSION=$( cat VERSION )" >>$GITHUB_ENV | ||
${GHAH} -c showEnv | ||
make | ||
- name: Install | ||
run: | | ||
cd prom/build && DESTDIR=${PROTO} make install | ||
cd ../../promhttp/build && DESTDIR=${PROTO} make install | ||
cd ${PROTO} && printf "${GITHUB_SHA}\n" > libprom.commit && \ | ||
tar cplzf ${{ runner.temp }}/libprom.tar.gz \ | ||
--xform="s|^.|libprom-${APP_VERSION}|" . | ||
- name: Upload binary archive | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: libprom-${{ env.DISTRO_NAME }}_${{ env.DISTRO_VERSION }}-${{ env.APP_VERSION }} | ||
path: ${{ runner.temp }}/libprom.tar.gz | ||
|
||
job_2a: | ||
name: Tests | ||
runs-on: ubuntu-20.04 | ||
# This job needs to do a lot more work than just building the libs. So | ||
# if building the libs fails, it does not make a lot of sense to try to run | ||
# any tests. Therefore we skip it automatically by building the libs first, | ||
# and thus save a lot of resources if the job fails. | ||
needs: job_1a | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: test | ||
env: | ||
DOCKER_IMAGE: debian:buster | ||
CI: 1 | ||
run: make | ||
debian-stretch: | ||
name: debian-stretch | ||
runs-on: ubuntu-latest | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install packages | ||
run: | | ||
echo 'man-db man-db/auto-update boolean false' | \ | ||
sudo debconf-set-selections | ||
sudo rm -f /var/lib/man-db/auto-update | ||
sudo apt-get update | ||
sudo apt-get install ${MISSING_BUILD_PKGS} | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Test run | ||
run: | | ||
make test | ||
job_1b: | ||
name: Docs | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: test | ||
env: | ||
DOCKER_IMAGE: debian:stretch | ||
CI: 1 | ||
run: make | ||
debian-jessie: | ||
name: debian-jessie | ||
runs-on: ubuntu-latest | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install packages | ||
run: | | ||
echo 'man-db man-db/auto-update boolean false' | \ | ||
sudo debconf-set-selections | ||
sudo rm -f /var/lib/man-db/auto-update | ||
sudo apt-get update | ||
# stupid debian shipped experimental and total broken ksh2020 as ksh | ||
# package and the stable one as ksh93 in focal. | ||
sudo apt-get install ksh93 || sudo apt-get install ksh | ||
sudo apt-get install ${MISSING_BUILD_PKGS} ${MISSING_DOC_PKGS} | ||
- name: Build | ||
run: | | ||
${GHAH} -c showEnv | ||
make docs | ||
- name: Upload docs archive | ||
uses: actions/upload-pages-artifact@v2 | ||
with: | ||
name: github-pages | ||
path: 'docs/html' | ||
|
||
job_2b: | ||
name: Github pages | ||
runs-on: ubuntu-20.04 | ||
needs: job_1b | ||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
pages: write | ||
id-token: write | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: test | ||
env: | ||
DOCKER_IMAGE: debian:jessie | ||
CI: 1 | ||
run: make | ||
- name: Deploy GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/bin/ksh93 | ||
|
||
typeset -r VERSION='1.0' | ||
|
||
LIC='[-?'"${VERSION}"' ] | ||
[-copyright?Copyright (c) 2023 Jens Elkner. All rights reserved.] | ||
[-license?CDDL 1.0]' | ||
SDIR=${.sh.file%/*} | ||
typeset -r FPROG=${.sh.file} | ||
typeset -r PROG=${FPROG##*/} | ||
|
||
# source in boiler plate code | ||
for H in log.kshlib man.kshlib ; do | ||
X=${SDIR}/$H | ||
[[ -r $X ]] && . $X && continue | ||
X=${ whence $H; } | ||
[[ -z $X ]] && print -u2 "$H not found - exiting." && exit 1 | ||
. $X | ||
done | ||
unset H | ||
|
||
Man.addFunc showUsage '' '[+NAME?showUsage - show usage information. Without any arg the short usage info for MAIN gets shown, for the named function in arg1 otherwise (if available). \bMAIN\b is the placeholder for the script itself.]' | ||
function showUsage { | ||
typeset WHAT="$1" X='--man' | ||
[[ -z ${WHAT} ]] && WHAT='MAIN' && X='-?' | ||
getopts -a "${PROG}" "${ print ${Man.FUNC[${WHAT}]}; }" OPT $X | ||
} | ||
|
||
Man.addFunc doMain '' '[+NAME?doMain - the main application loop alias script entry point.]' | ||
function doMain { | ||
typeset X ARGS=( "$@" ) | ||
integer C=0 | ||
|
||
for X in ${CMD} ; do | ||
[[ -z $X || $X == 'doMain' ]] && continue | ||
$X "${ARGS[@]}" || return $? | ||
(( C++ )) | ||
done | ||
(( C )) || showUsage | ||
} | ||
|
||
Man.addFunc showEnv '' '[+NAME?showEnv - show the current environment.] | ||
[+DESCRIPTION?Shows the main parameters of the working environment. If an argument gets passed, all environment variables currently set will be shown, otherwise all beginning with \bGITHUB_\b and some specials, only.] | ||
\n\n[\aarg\a]' | ||
function showEnv { | ||
Log.printMarker | ||
if [[ -n $1 ]]; then | ||
set | ||
else | ||
# GITHUB_{PATH,ENV,SHA,RUN_ID} sind bei jedem run anders (leere files) | ||
set | egrep '^(GITHUB|RUNNER)_' | ||
print "GHAH=${GHAH}" | ||
set | egrep -v '^((GITHUB|RUNNER)_|GHAH=)' | ||
fi | ||
Log.printMarker | ||
typeset T=${ nproc; } M=${ grep '^model name' /proc/cpuinfo | head -1; } | ||
print "${M// :/: ${T}x }" | ||
egrep '^(Mem|Swap)' /proc/meminfo | ||
Log.printMarker | ||
uname -a | ||
Log.printMarker | ||
networkctl | ||
networkctl status | ||
Log.printMarker | ||
} | ||
|
||
Man.addFunc MAIN '' '[+NAME?'"${PROG}"' - helper script for Hets Github Actions.] | ||
[+DESCRIPTION?This is a little helper script to circumvent problems, code repetitions and other shortcomings of Github Action [design]]. Most functions are Hets repo related and should not be used on other repos unless properly adjusted.] | ||
[+?All operands to this script get passed to the related functions as is. So take care if you call several functions at once.] | ||
[h:help?Print this help and exit.] | ||
[F:functions?Print out a list of all defined functions. Just invokes the \btypeset +f\b builtin.] | ||
[H:usage]:[function?Show the usage information for the given function if available and exit. Functions with no such info or starting with an underline are internal and should not be invoked using the \b-c ...\b option. See also option \b-F\b.] | ||
[T:trace]:[fname_list?A comma or whitspace separated list of function names, which should be traced during execution. Use \bALL\b for all available function.] | ||
[+?] | ||
[c:cmd]:[fname_list?Execute the functions in the given list of comma separated function names \afname_list\a. Functions get called one after another. The EXIT code is the one of the last executed function. If a function exits with != 0, all remaining functions in the list get skipped.] | ||
' | ||
X="${ print ${Man.FUNC[MAIN]} ; }" | ||
unset CMD; typeset CMD | ||
while getopts "${X}" option ; do | ||
case "${option}" in | ||
h) showUsage MAIN ; exit 0 ;; | ||
F) typeset +f ; exit 0 ;; | ||
H) if [[ ${OPTARG%_t} != ${OPTARG} ]]; then | ||
${OPTARG} --man # self-defined types | ||
else | ||
showUsage "${OPTARG}" # function | ||
fi | ||
exit 0 | ||
;; | ||
T) if [[ ${OPTARG} == 'ALL' ]]; then | ||
typeset -ft ${ typeset +f ; } | ||
else | ||
typeset -ft ${OPTARG//,/ } | ||
fi | ||
;; | ||
c) CMD+=( ${OPTARG//,/ } ) ;; | ||
*) showUsage ;; | ||
esac | ||
done | ||
X=$((OPTIND-1)) | ||
shift $X | ||
|
||
doMain "$@" | ||
# vim: ts=4 sw=4 filetype=sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# to be able to distinguish this scripts messages from other output | ||
typeset -T LogObj_t=( | ||
typeset -Sh 'Color for info messages' GREEN='38;5;232;48;5;118' #'1;30;102'; | ||
typeset -Sh 'Color for warning messages' BLUE='38;5;21;48;5;118' #'1;34;102'; | ||
typeset -Sh 'Color for fatal messages' RED='38;5;9;48;5;118' #'1;31;102'; | ||
function log { | ||
print -u2 "\E[1;$2m${ date +%T; } $1:\E[0m $3" | ||
} | ||
typeset -Sfh ' log a message to stderr' log | ||
function info { | ||
_.log "INFO" ${_.GREEN} "$*" | ||
} | ||
typeset -Sfh ' log a info message to stderr' info | ||
function warn { | ||
_.log "WARN" ${_.BLUE} "$*" | ||
} | ||
typeset -Sfh ' log a warning message to stderr' warn | ||
function fatal { | ||
_.log "FATAL" ${_.RED} "$*" | ||
} | ||
typeset -Sfh ' log a fatal error message to stderr' fatal | ||
function printMarker { | ||
typeset COLOR="$1" | ||
print -f '\E[1;%sm----------------------------------------------------------------------------\E[0m\n' "${COLOR:-${_.GREEN}}" | ||
} | ||
typeset -Sfh ' print a marker line to stdout' printMarker | ||
) | ||
LogObj_t Log |
Oops, something went wrong.