-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (82 loc) · 3.71 KB
/
self_hosted.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
# This is a basic workflow to help you get started with Actions
name: SpinW Tests
# Controls when the action will run.
on:
push:
branches: [ main ]
pull_request:
branches: [ main, development ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# List which servers to run here separated by commas
# Valid values are: linux, windows, macos
env:
SERVERS: "linux, windows"
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow creates a VM labeled `matlab_linux`
create_runners:
# The type of runner that the job will run on
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.create-vm.outputs.matrix }}
# Don't run if we ask to skip CI
if: "!contains(github.event.head_commit.message, '[ci skip]')"
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Creates the new VM
- name: Create VM
id: create-vm
run: |
sudo apt-get install openssl
# The encrypted token has a newline; use tr to replace it with underscore
# decrypted on server with `openssl enc -aes-256-cbc -d -a -pbkdf2 -k $OPENSSL_PW`
encrypted_pat=$(echo ${{ secrets.PERSONAL_TOKEN }} | \
openssl enc -e -aes-256-cbc -pbkdf2 -a -k ${{ secrets.OPENSSL_PW }} | \
tr "\n" "_")
# ID is used to distinguish concurrent jobs (separate vagrant folders)
ID="${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
# Sets the IDs as output (set above after runs-on) to be used in the matrix in the next job
OSMATRIX=$(echo '"${{ env.SERVERS }}"' | sed "s/\s//g" | jq "split(\",\")|map(.+\"_$ID\")")
echo "::set-output name=matrix::{\"os\":$(echo $OSMATRIX)}"
DATA="{\"ghcontrol\":\"create\", \"servers\":\"${{ env.SERVERS }}\", \"PAT\":\"$encrypted_pat\", \"ID\":\"$ID\"}"
curl -k -v --fail \
-H "Content-Type: application/json" \
--data "{\"data\":$DATA, \"repository\":\"$GITHUB_REPOSITORY\"}" \
${{ secrets.WEBHOOK_URL }} | jq -e '.success == "true"'
# This workflow runs the actual unit tests if we have suceeded creating the VM
unit_tests:
needs: create_runners
strategy:
matrix: ${{ fromJson(needs.create_runners.outputs.matrix) }}
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: Run a one-line script
run: |
echo Hello, world!
# Runs a set of commands using the MATLAB shell
- name: Run a multi-line script
run: |
matlab -nosplash -nodesktop -nojvm -r "disp('Hello World'); exit"
# This workflow always runs after the creating and unit tests, destroying the VM
destroy_runners:
needs: [create_runners, unit_tests]
if: always()
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Destroy the VM
- name: Invoke destroying hook
run: |
ID="${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
DATA="{\"ghcontrol\":\"destroy\", \"servers\":\"${{ env.SERVERS }}\", \"ID\":\"$ID\"}"
curl -k -v --fail \
-H "Content-Type: application/json" \
--data "{\"data\":$DATA, \"repository\":\"$GITHUB_REPOSITORY\"}" \
${{ secrets.WEBHOOK_URL }} | jq -e '.success == "true"'