Skip to content

Commit

Permalink
Add windows-test GH workflow control to tagly buildkite pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Dec 22, 2023
1 parent 7fdd744 commit ae4ca12
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 6 deletions.
17 changes: 11 additions & 6 deletions .buildkite/tagly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ env:
TMPDIR: "/cache"

steps:
- label: 'Build Docker Image (linux)'
key: build-docker
command:
- "mkdir -p config && echo '{ outputs = _: { dockerHubRepoName = \"cardanofoundation/cardano-wallet\"; }; }' > config/flake.nix"
- "nix build .#pushDockerImage --override-input hostNixpkgs \"path:$(nix eval --impure -I $NIX_PATH --expr '(import <nixpkgs> {}).path')\" --override-input customConfig path:./config -o docker-build-push"
- "./docker-build-push"
# - label: 'Build Docker Image (linux)'
# key: build-docker
# command:
# - "mkdir -p config && echo '{ outputs = _: { dockerHubRepoName = \"cardanofoundation/cardano-wallet\"; }; }' > config/flake.nix"
# - "nix build .#pushDockerImage --override-input hostNixpkgs \"path:$(nix eval --impure -I $NIX_PATH --expr '(import <nixpkgs> {}).path')\" --override-input customConfig path:./config -o docker-build-push"
# - "./docker-build-push"
# agents:
# system: x86_64-linux
- label: Run windows tests
key: windows-tests
command: "./scripts/buildkite/run-windows-tests.sh windows.yml $BUILDKITE_TAG"
agents:
system: x86_64-linux
92 changes: 92 additions & 0 deletions scripts/buildkite/run-windows-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#! /usr/bin/env bash

set -euo pipefail

WORKFLOW_FILE=$1
echo "Workflow file is $WORKFLOW_FILE"

REF=$2
echo "Ref is $REF"

TOKEN=$GITHUB_TOKEN
GH_USER="cardano-foundation"
REPO="cardano-wallet"

WORKFLOW_ID=$(tr -dc '0-9' </dev/urandom | head -c 16 ; echo)
echo "Workflow id is $WORKFLOW_ID"
NOW=$(date +"%Y-%m-%dT%H:%M")
LATER=$(date -d "-5 minutes" +"%Y-%m-%dT%H:%M")
DATE_FILTER=$(echo "$NOW-$LATER")

JSON="{\"ref\":\"$REF\",\"inputs\":{\"id\":\"$WORKFLOW_ID\"}}"

echo "Triggering workflow $WORKFLOW_FILE with id $WORKFLOW_ID"
curl -s \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
"https://api.github.com/repos/$GH_USER/$REPO/actions/workflows/$WORKFLOW_FILE/dispatches" \
-d $JSON

INFO="null"
COUNT=1
ATTEMPTS=10
CHECK="0"

echo "Waiting for workflow to start to retrieve run id..."
until [ $CHECK -eq $WORKFLOW_ID ] || [ $COUNT -eq $ATTEMPTS ]

do

echo -e "$(( COUNT++ ))..."
sleep 5s

# get latest workflows run ids
INFO=$(curl -s \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
"https://api.github.com/repos/$GH_USER/$REPO/actions/runs?created:<$DATE_FILTER" | jq -r '.workflow_runs[].id' | grep -m1 "")

# get the run id that matches the workflow identifier
CHECK=$(curl -s \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
"https://api.github.com/repos/$GH_USER/$REPO/actions/runs/$INFO/jobs" | jq -r '.jobs[].steps[].name' | grep -m1 $WORKFLOW_ID || echo "0")
done

echo "Run id is $INFO"

status="null"

echo "Waiting for workflow run to complete..."
until [ $status == "completed" ] || [ $status == "failure" ] || [ $status == "success" ]

do
status=$(curl -s \
-X GET \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
"https://api.github.com/repos/$GH_USER/$REPO/actions/runs/$INFO" \
| jq -r '.status'\
)
sleep 10s
done

case $status in
"completed")
echo "Workflow completed"
;;
"failure")
echo "Workflow failed"
exit 1
;;
"success")
echo "Workflow succeeded"
;;
*)
echo "Workflow status unknown: $status"
exit 1
;;
esac

0 comments on commit ae4ca12

Please sign in to comment.