-
Notifications
You must be signed in to change notification settings - Fork 107
126 lines (113 loc) · 4.59 KB
/
test.yml
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Unit Testing
on:
repository_dispatch:
types:
- test-command
push:
branches:
- master
jobs:
configure:
name: Preliminary configuration
runs-on: ubuntu-latest
outputs:
commit-ref: ${{ steps.configure.outputs.commit-ref }}
repo-suffix: ${{ steps.configure.outputs.repo-suffix }}
repo-name: ${{ steps.configure.outputs.repo-name }}
steps:
- name: Configure
id: configure
run: |
# The ref of the commit to checkout (do not use the merge commit if pull request)
if [ "${{ github.event_name }}" == "repository_dispatch" ]; then
echo "commit-ref=${{ github.event.client_payload.pull_request.head.sha }}" >> $GITHUB_OUTPUT
elif [ "${{ steps.get_version.outputs.VERSION }}" != "" ]; then
echo "commit-ref=${{ steps.get_version.outputs.VERSION }}" >> $GITHUB_OUTPUT
else
echo "commit-ref=${{ github.sha }}" >> $GITHUB_OUTPUT
fi
if [ "${{ github.event_name }}" != "repository_dispatch" ]; then
echo "repo-name=${{ github.repository }}" >> $GITHUB_OUTPUT
else
echo "repo-name=${{ github.event.client_payload.github.payload.repository.full_name }}" >> $GITHUB_OUTPUT
fi
# Since we are using a repository-dispatch event, we have to explicitly set a run check. We initialize it to a "pending" state.
- uses: octokit/[email protected]
name: "Initialize run check to 'pending'"
with:
route: POST /repos/${{ github.repository }}/statuses/${{ steps.configure.outputs.commit-ref }}
state: "pending"
description: "Unit Test status"
context: "Unit Test"
target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
GITHUB_TOKEN: ${{ secrets.CI_TOKEN }}
if: ${{ github.event_name == 'repository_dispatch' }}
test:
name: Launch Test
runs-on: ubuntu-20.04
needs: configure
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
ref: "${{ needs.configure.outputs.commit-ref }}"
repository: "${{ needs.configure.outputs.repo-name }}"
persist-credentials: false
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ matrix.component }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ matrix.component }}-buildx-
- name: Build (and Publish) liqo-test image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64
tags: |
ghcr.io/${{ github.repository_owner }}/liqo-test:${{ needs.configure.outputs.commit-ref }}
push: false
load: true
file: build/liqo-test/Dockerfile
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# This ugly bit is necessary if you don't want your cache to grow forever
# till it hits GitHub's limit of 5GB.
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Launch Test (Docker Container)
uses: addnab/docker-run-action@v3
with:
options: |
--mount type=bind,src=${{ github.workspace }},dst=/go/src/liqotech/liqo
--workdir /go/src/liqotech/liqo
--privileged=true
image: ghcr.io/${{ github.repository_owner }}/liqo-test:${{ needs.configure.outputs.commit-ref }}
run: |
go-acc ./... --ignore liqo/test/e2e
# Since we are using a repository-dispatch event, we have to explicitly set a run check. We update it to the actual status.
- uses: octokit/[email protected]
name: "Update run check status"
with:
route: POST /repos/${{ github.repository }}/statuses/${{ needs.configure.outputs.commit-ref }}
state: "${{ job.status }}"
description: "Unit Test status"
context: "Unit Test"
target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
GITHUB_TOKEN: ${{ secrets.CI_TOKEN }}
if: ${{ !cancelled() && github.event_name == 'repository_dispatch' }}
- name: Send coverage
uses: shogo82148/[email protected]
with:
path-to-profile: coverage.txt
if: github.event_name == 'push'