-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (45 loc) · 2.28 KB
/
build-test-pull-request.yml
File metadata and controls
57 lines (45 loc) · 2.28 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
name: Build and test on pull request
on:
pull_request:
branches: ['*']
jobs:
select-runner:
runs-on: ubuntu-latest
outputs:
runner-label: ${{ steps.set-runner.outputs.runner-label }}
steps:
- name: Set runner
id: set-runner
run: |
# This script checks if the pull request has the label "run-self-hosted" and if so, and a self-hosted runner is available, runs the job on the self-hosted runner.
runner_label="ubuntu-latest"
trap 'echo "runner-label=$runner_label" >> $GITHUB_OUTPUT' ERR
if [ "${{ github.event_name }}" = "pull_request" ]; then
labels=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" "${{ github.event.pull_request.url }}/labels")
if echo "$labels" | jq -e '.[] | select(.name == "run-self-hosted")' > /dev/null; then
runners=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runners")
available=$(echo "$runners" | jq '.runners[] | select(.status == "online" and .busy == false and .labels[] .name == "self-hosted")')
if [ -n "$available" ]; then
runner_label="self-hosted"
fi
fi
fi
echo "runner-label=$runner_label" >> $GITHUB_OUTPUT
automation-tests:
needs: select-runner
runs-on: ${{ needs.select-runner.outputs.runner-label }}
steps:
- name: Log runner label
run: echo "Running on runner ${{ needs.select-runner.outputs.runner-label }}"
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: yarn install
- name: Build services
run: yarn run build:all
- name: Run tests
run: yarn test --passWithNoTests