-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (93 loc) · 4 KB
/
ci.yaml
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
name: CI
# TODO Looks like workflows ARE reusable now: https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow
# Controls when the action will run.
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]
# Specify defaults for all jobs' `run` blocks.
# See:
# https://github.community/t/use-working-directory-for-entire-job/16747/9
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_iddefaultsrun
# https://github.community/t/github-actions-configure-defaults-option/18438/3
defaults:
run:
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
gitUserName: ${{ github.actor }}
gitUserEmail: ${{ github.actor }}@users.noreply.github.com
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Job 1. Handles everything related to the client/ folder
ci-build-and-upload-artifacts:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Specify defaults for all runs/steps.
defaults:
run:
# Specify directory in which to run all subsequent steps/commands
#
# If using a monolith with `./client/` and `./server/` directories:
# working-directory: ./client
working-directory: ./
# outputs:
# ci-build-output:
# description: "CI - Cache build output"
# # value:
# 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
- name: Checkout repository branch
uses: actions/checkout@v3
- name: Set NodeJS version
uses: actions/setup-node@v3
with:
node-version: 16
- name: Client CI - Download cache
uses: actions/cache/restore@v3
env:
cache-name: ci-cache
with:
path: |
node_modules
dist
package.json
package-lock.json
key: ${{ env.cache-name }}-${{ runner.os }}-${{ hashFiles('package.json', './src/**', './test/**', './tests/**', './config/**', './mocks/**') }}
# Ensure old cache is deleted so that the build step's cache request isn't ignored
#
# See:
# - https://stackoverflow.com/questions/63521430/clear-cache-in-github-actions/64819132#64819132
- name: Client CI - Clear caches
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_RUN_ID: ${{ github.run_id }}
CACHE_NAME: ${{ env.cache-name }}-${{ runner.os }}-${{ hashFiles('package.json', './src/**', './test/**', './tests/**', './config/**', './mocks/**') }}
run: |
CACHES_API_URL="https://api.github.com/repos/$(gh repo view --json owner --jq '.owner.login')/$(gh repo view --json name --jq '.name')/actions/caches"
cacheIds=($(gh api "${CACHES_API_URL}" --jq ".actions_caches[] | select(.key | contains(\"${{ env.CACHE_NAME }}\")) | .id"))
echo "Deleting cache IDs: ${cacheIds[@]}..."
( for cacheId in ${cacheIds[@]}; do gh api --method DELETE "${CACHES_API_URL}/$cacheId"; done; )
- name: Client Verify
# Import reusable GitHub Action logic via `uses`
uses: ./.github/workflows/actions/client
- name: Client cache build and install artifacts
id: ci-cache
uses: actions/cache/save@v3
env:
cache-name: ci-cache
with:
path: |
node_modules
dist
package.json
package-lock.json
key: ${{ env.cache-name }}-${{ runner.os }}-${{ hashFiles('package.json', './src/**', './test/**', './tests/**', './config/**', './mocks/**') }}
# restore-keys: |
# ${{ env.cache-name }}-${{ runner.os }}-
# ${{ env.cache-name }}-