-
Notifications
You must be signed in to change notification settings - Fork 8
154 lines (133 loc) · 5.79 KB
/
test-dev-tracks.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
##############################################################################
# Instruqt Github Actions Workflow
#
# This workflow file and its actions will run a validate/push/test cycle on
# on a directory of instruqt tracks. All the tracks in the directory must
# belong to the same Instruqt team. Tracks tagged with `skip-ci`, `ci-skip`,
# or `no-ci` will not be included in this workflow.
#
# Only DEV tracks that are not in maintenance mode will be tested. Each DEV
# track should have a corresponding PROD track. The workflow will loop through
# the $TRACK_DIR and test tracks when:
#
# * A matching DEV version exists on play.instruqt.com
# * Dev track is not in maintenance mode
# * Track does not include any of the skip tags: no-ci, ci-skip, skip-ci
#
# This workflow will run on every pull request to the main/master branch.
#
# To keep run times efficient put your unused DEV tracks into maintenance mode
# or delete them when you're done!
##############################################################################
name: test-dev-tracks
env:
# Store your Instruqt API key and track directory as a secret
# and variable in your Github repo.
TRACK_DIR: ${{ vars.TRACK_DIR }}
INSTRUQT_TOKEN: ${{ secrets.INSTRUQT_TOKEN }}
# Leave this alone, it will be auto-populated.
TRACKS: ""
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
on:
pull_request:
types: [opened, reopened, edited, synchronize]
workflow_dispatch:
jobs:
GetTracks:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install yq Package
uses: ./.github/actions/install-yq
- name: Create Matrix Data
run: |
# This function checks to see whether any of no-ci, skip-ci, or ci-skip exist.
function skip_enabled() {
if ! [[ -f "$1/track.yml" ]]; then
echo "Error: $1 is not a valid track directory"
return 1
fi
# Run the yq command to check the tags array and return the result
yq_result=$(yq '.tags | any_c(test("(?i)no-ci|skip-ci|ci-skip"))' "$1/track.yml")
echo $yq_result
}
cd $TRACK_DIR
# Build a list of tracks to test. Does not include tracks that are tagged
# with no-ci, skip-ci, or ci-skip or tracks in maintenance mode or dev tracks
# that were accidentally commited to your git repo.
for t in $(ls -d *); do
if [[ $(yq '.slug | test(".*-dev$")' $t/track.yml) == 'true' ]]; then
echo "Track $t is a dev track, please remove it from your repo!"
exit 1
elif [[ $(yq '.maintenance' $t/track.yml) == 'true' ]]; then
echo "Track $t is in maintenance mode, skipping."
elif [[ $(skip_enabled $t) == 'true' ]]; then
echo "Skip CI tag found, skipping $t."
else
echo "Adding $t to test matrix"
CI_TRACKS+=("$t")
fi
done
# This mess creates a string of properly escaped JSON for the next job to use.
escaped_json_string=$(printf "%s\n" "${CI_TRACKS[@]}" | jq -R -s -c 'split("\n")[:-1]' | sed 's/"/\\\"/g')
echo $escaped_json_string
echo TRACKS="{\\\"tracks\\\":$escaped_json_string}" >> $GITHUB_ENV
- id: set-matrix
run: |
echo "matrix=${{ env.TRACKS }}" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
TestDevTracks:
runs-on: ubuntu-latest
# Ensures that you can't run this action on the main or master branch
if: ${{ needs.GetTracks.outputs.matrix != '{"tracks":[""]}' && needs.GetTracks.outputs.matrix != '' }} && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main'
needs: GetTracks
strategy:
matrix: ${{ fromJson(needs.GetTracks.outputs.matrix) }}
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install yq Package
uses: ./.github/actions/install-yq
# Here we use a trick to get the dev tracks that need testing.
# We convert each PROD track from our matrix into a DEV track locally.
- name: Create dev track from prod track
run: |
# Change into the track directory
cd ${{ env.TRACK_DIR }}/${{ matrix.tracks }}
# Strip out the track ids
echo "Converting track to dev version..."
for file in $(find . -name assignment.md); do
yq eval --inplace --front-matter=process 'del(.id)' $file
done
# Remove IDs and update slugs/titles
yq eval --inplace 'del(.id)' track.yml
yq eval --inplace '.slug += "-dev"' track.yml
yq eval --inplace '.title = "DEV - " + .title' track.yml
# Replace prod tag with dev tag
yq eval --inplace 'del(.tags[] | select(. == "prod"))' track.yml
yq eval --inplace '.tags = .tags + "dev" ' track.yml
# Then, we attempt to pull these DEV tracks from the Instruqt platform.
# This ensures you get the latest version of the dev track.
# Only dev tracks that are not in maintenance mode are tested!
- name: Pull track from instruqt
id: pull-track
uses: ./.github/actions/pull-track
with:
path: ${{ env.TRACK_DIR }}/${{ matrix.tracks }}
continue-on-error: true
- name: Track Validate
id: validate-track
uses: ./.github/actions/validate-track
with:
path: ${{ env.TRACK_DIR }}/${{ matrix.tracks }}
if: steps.pull-track.outcome == 'success'
- name: Track Test
id: test-track
uses: ./.github/actions/test-track
with:
path: ${{ env.TRACK_DIR }}/${{ matrix.tracks }}
if: steps.validate-track.outcome == 'success'