-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (126 loc) · 4.47 KB
/
ci.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: CI
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
cancel-in-progress: true
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
cache: 'npm'
- name: Update npm version
run: npm update npm -g
- name: Install dependencies
run: npm ci
- name: Run linting
run: npm run lint
- name: Validate current commit (last commit) with commitlint
if: github.event_name == 'push'
run: npx commitlint --from HEAD~1 --to HEAD --verbose
- name: Validate PR commits with commitlint
if: github.event_name == 'pull_request'
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
type-check:
name: Type check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
cache: 'npm'
- name: Update npm version
run: npm update npm -g
- name: Install dependencies
run: npm ci
- name: Run type check
run: npm run check
test:
name: Playwright test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
cache: 'npm'
- name: Update npm version
run: npm update npm -g
- name: Install dependencies
run: npm ci
- name: Install Playwright dependencies
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npm run test
check-deploy:
name: Check if deploy is needed
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
deployNext: ${{ steps.checkCommitMessagesForNextChanges.outputs.deployNext }}
permissions: read-all
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get last workflow run SHA
id: lastWorkflowRun
run: |
export SHA=$(gh run list --json headSha | jq -r '.[1].headSha')
echo "lastWorkflowRunSha=$SHA" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}
- name: Check commit messages for Next changes
id: checkCommitMessagesForNextChanges
run: |
if git log --pretty=format:"%s" ${{ steps.lastWorkflowRun.outputs.lastWorkflowRunSha }}..HEAD | grep -q -E '\(next\):|^feat:|^fix:|^ci:|^refactor:|^chore:'; then
echo "Commit messages since last deploy contain a repo wide or Next change"
echo "deployNext=true" >> "$GITHUB_OUTPUT"
else
echo "Commit messages since last deploy do not contain a repo wide or Next change"
echo "deployNext=false" >> "$GITHUB_OUTPUT"
fi
changes-since-last-deploy:
name: Compare changes since last deploy
runs-on: ubuntu-latest
needs: [lint, type-check, test, check-deploy]
if: ${{ needs.check-deploy.outputs.deployNext == 'true' }}
environment:
name: github
url: ${{steps.changes.outputs.url}}
permissions: read-all
steps:
- uses: actions/checkout@v4
- name: Changes since last deploy
id: changes
run: |
export SHA=$(gh run list --json databaseId | jq -r ".[] | .databaseId" | while read -r run_id; do gh run view $run_id --json jobs,headSha | jq -r '. | select(.jobs[] | .name == "Deploy to production" and .status == "completed" and .conclusion == "success") | .headSha' | grep . && break; done | head -n 1)
echo "url=https://github.com/${{ github.repository }}/compare/$SHA...${{ github.sha }}" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}
deploy-production:
name: Deploy to production
runs-on: ubuntu-latest
needs: [changes-since-last-deploy]
if: github.ref == 'refs/heads/main'
environment:
name: production
url: https://epoxide.se
concurrency:
group: production
cancel-in-progress: true
steps:
- name: Trigger Coolify deployment
run: |
curl --request GET '${{ secrets.COOLIFY_WEBHOOK_URL }}' --header 'Authorization: Bearer ${{ secrets.COOLIFY_API_TOKEN }}'