-
Notifications
You must be signed in to change notification settings - Fork 1
75 lines (64 loc) · 2.65 KB
/
main.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
name: Linting, prettier and Testing
on: #this workflow runs on pull requests and pushes to main or master
pull_request:
branches: [main, master]
push:
branches: [main, master]
#this is a list of all jobs
jobs:
check-pr-sync-with-main:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
- name: Create and checkout a temporary branch from main
run: |
git fetch origin main
git checkout -b temp-branch origin/main
- name: Merge PR branch into temporary branch
run: |
git merge ${{ github.event.pull_request.head.sha }} --no-edit || true
- name: Check for differences
run: |
if git diff --exit-code ${{ github.event.pull_request.head.sha }} temp-branch; then
echo "No differences found. The PR branch is up-to-date with the latest main branch."
else
echo "Differences found. The PR branch is not up-to-date with the latest main branch."
exit 1
fi
linting:
runs-on: ubuntu-latest
needs: check-pr-sync-with-main
steps:
- name: Checkout #checks out our current branch so this runner has the latest code
uses: actions/checkout@v4 #uses means that it is a pre-defined action supplied by GitHub.
- name: Setup Node
uses: actions/setup-node@v3 #this is also a pre-defined action
with:
node-version: 20
- name: NPM Install #we now need to install all our dependencies in this environment
run: npm ci #npm clean install - does not write to package.json
- name: Run linting
run: npm run lint
- name: Run prettier
run: npm run prettierW
testing: #name of first job
runs-on: ubuntu-latest #sets the env which this job runs on
needs: [linting, check-pr-sync-with-main]
steps: #defines the steps necessary
- name: Checkout #checks out our current branch so this runner has the latest code
uses: actions/checkout@v4 #uses means that it is a pre-defined action supplied by GitHub.
- name: Setup Node
uses: actions/setup-node@v3 #this is also a pre-defined action
with:
node-version: 20
- name: NPM Install #we now need to install all our dependencies in this environment
run: npm ci #npm clean install - does not write to package.json
- name: Run tests #if npm test throws and error this workflow fails.
run: npm test