Skip to content

Commit

Permalink
ci: Add GitHub action to collect build statistics
Browse files Browse the repository at this point in the history
Also reorganise the scripts used for workflows.
  • Loading branch information
rvl committed May 13, 2021
1 parent dc3d14a commit 08e0210
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 8 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/ci-stats.yml
@@ -0,0 +1,52 @@
name: Stats

on:
status:
push:
branches:
- master
- rvl/adp-921/optimize-hydra-eval

jobs:
stats:
env:
branch: ci-stats
if: ${{ (github.ref == 'refs/heads/master' && (github.event.state == 'success' || github.event.state == 'failure') && github.event.context == 'ci/hydra-build:required') || github.ref == 'refs/heads/rvl/adp-921/optimize-hydra-eval' }}
runs-on: ubuntu-20.04
steps:
- name: '❄ Wait for Hydra build'
uses: rvl/hydra-build-products-action@master
id: hydra
with:
hydra: https://hydra.iohk.io
statusName: ci/hydra-eval
jobs: required
requiredJob: required
project: Cardano
jobset: cardano-wallet
badge: "${{ github.event_name == 'status' && 'yes' || 'no' }}"

- name: '📥 Checkout Code'
uses: actions/checkout@v2

- name: '📥 Checkout Stats'
uses: actions/checkout@v2
with:
ref: ${{ env.branch }}
fetch-depth: 1
path: _build

- name: '📘 Publish Stats'
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rvl/adp-921/optimize-hydra-eval' }}
working-directory: _build
run: |
echo '${{ steps.hydra.outputs.evaluation }}' > eval.json
echo '${{ steps.hydra.outputs.builds }}' > builds.json
echo '${{ steps.hydra.outputs.timings }}' > timings.json
../scripts/gh/update-stats.sh '${{ env.branch}}' eval.json builds.json timings.json
- name: '📛 Update Badge'
if: ${{ github.event_name == 'status' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rvl/adp-921/optimize-hydra-eval') }}
working-directory: _build
run: |
../scripts/gh/update-badge.sh '${{ env.branch}}' <(echo '${{ steps.hydra.outputs.badge }}')
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Expand Up @@ -38,7 +38,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: '📥 Checkout repository'
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: '📸 Build Documentation'
run: |
Expand All @@ -47,7 +47,7 @@ jobs:
else
tag=""
fi
./scripts/update-docs.sh _build $tag
./scripts/gh/update-docs.sh _build $tag
- name: '📘 Publish'
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
Expand All @@ -59,13 +59,14 @@ jobs:
keep_files: true
user_name: 'William King Noel Bot'
user_email: 'adrestia@iohk.io'
commit_message: 'docs: ${{ github.event.head_commit.message }}'

bump_sh:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-20.04
steps:
- name: '📥 Checkout repository'
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: 'Set up Ruby'
uses: ruby/setup-ruby@v1
with:
Expand All @@ -75,7 +76,7 @@ jobs:
- name: 'Install dependencies'
run: 'sudo snap install yq'
- name: 'Update Release in Bump.sh'
run: './scripts/update-bump.sh'
run: './scripts/gh/update-bump.sh'
env:
BUMP_SH_DOC_ID: ${{ secrets.BUMP_SH_DOC_ID }}
BUMP_SH_TOKEN: ${{ secrets.BUMP_SH_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Expand Up @@ -112,7 +112,7 @@ jobs:
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
fetch-depth: 1
- name: "Advance windows-tests-pass and all-tests-pass branches"
if: github.ref == 'ref/heads/master'
shell: bash
Expand Down
31 changes: 31 additions & 0 deletions scripts/gh/common.sh
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034 # Sourcing script uses variables

check_branch() {
branch=$(git branch --show-current)
if [ -n "$1" ] && [ "$1" != "$branch" ]; then
echo "error: Current branch $branch is not the intended destination branch $1" > /dev/stderr
exit 2
fi
}

exit_unless_index_changed() {
if git diff-index --cached --quiet HEAD --; then
echo "No changes to commit, exiting."
exit 0
fi
}

commit_and_push() {
exit_unless_index_changed
git commit -m "$1$commit_msg_suffix"
if [ -z "${NO_PUSH:-}" ]; then
git push
fi
}

export GIT_AUTHOR_NAME='William King Noel Bot'
export GIT_AUTHOR_EMAIL='adrestia@iohk.io'

commit_msg_suffix=" ${GITHUB_SHA:-update}"
dir=$(date +%Y-%m)
23 changes: 23 additions & 0 deletions scripts/gh/update-badge.sh
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -euo pipefail

source "${BASH_SOURCE%/*}/common.sh"

dest_branch=${1:-}
badge_url=${2:-}

if [ -z "$badge_url" ]; then
echo "usage: $0 DEST_BRANCH BADGE_URL"
exit 1
fi

check_branch "$dest_branch"

out="hydra-badge.svg"

echo "GET $badge_url"
curl --fail "$badge_url" -o "$out"
git add "$out"

commit_and_push "badge: hydra"
File renamed without changes.
8 changes: 5 additions & 3 deletions scripts/update-docs.sh → scripts/gh/update-docs.sh
Expand Up @@ -2,7 +2,9 @@

set -euo pipefail

root=$(cd "$(dirname "$0")"/..; pwd)
source "${BASH_SOURCE%/*}/common.sh"

src=$(cd "${BASH_SOURCE%/*}/../.."; pwd)
out="${1:-}"
tag="${2:-}"

Expand All @@ -20,5 +22,5 @@ else
fi

echo '*** Building documentation for' "$what"
mkdir -p "$dest"
cp -Rv "$root"/specifications/api/* "$dest"
mkdir -pv "$dest"
cp -Rv "$src"/specifications/api/* "$dest"
28 changes: 28 additions & 0 deletions scripts/gh/update-stats.sh
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -euo pipefail

source "${BASH_SOURCE%/*}/common.sh"

dest_branch="${1:-}"
eval="${2:-}"
builds="${3:-}"
timings="${4:-}"

if [ -z "$timings" ]; then
echo "usage: $0 DEST_BRANCH EVAL.json BUILDS.json TIMINGS.json"
exit 1
fi

check_branch "$dest_branch"

eval_id=$(jq .id "$eval")

out="$dir/hydra/eval-$eval_id.json"

mkdir -p "$(dirname "$out")"

jq --slurpfile evals "$eval" --slurpfile builds "$builds" '$evals[0] as $eval | { eval: $eval.id, builds: { required: $builds[0].required|{id,finished,buildstatus,buildmetrics} }, rev: $eval.jobsetevalinputs["cardano-wallet"].revision, timings: . }' "$timings" > "$out"

git add "$out"
commit_and_push "stats: hydra"

0 comments on commit 08e0210

Please sign in to comment.