-
Notifications
You must be signed in to change notification settings - Fork 4
142 lines (117 loc) · 3.6 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
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
name: CI Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- '**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20.17.0'
- name: Install dependencies
run: npm ci
- name: Build the project
run: npm run build
- name: Run linter
run: npm run lint
- name: Run tests
run: npm run test:coverage
- name: Report coverage to Codacy
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: wget -qO - https://coverage.codacy.com/get.sh | bash -s -- report -r ./coverage/cobertura-coverage.xml
- name: Upload build artifacts
uses: actions/upload-artifact@v3
if: github.ref == 'refs/heads/main'
with:
name: build-artifacts
path: ./dist
release:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
- name: List files in dist folder
run: |
if [ -z "$(ls -A ./dist)" ]; then
ls -la ./dist
echo "Error: dist folder is empty"
exit 1
else
echo "dist folder contains files"
fi
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20.17.0'
- name: Install dependencies
run: npm ci
- name: Run semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
- name: Upload release artifacts
uses: actions/upload-artifact@v3
with:
name: release-artifacts
path: |
./package.json
./package-lock.json
./CHANGELOG.md
docker:
runs-on: ubuntu-latest
needs: release
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download release artifacts
uses: actions/download-artifact@v3
with:
name: release-artifacts
- name: Get build arguments
id: vars
run: |
BUILD_DATE=$(date +%Y-%m-%dT%T%z)
BUILD_VERSION=$(awk -F\" '/"version":/ {print $4}' package.json)
BUILD_REVISION=$(git rev-parse --short HEAD)
echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_ENV
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
echo "BUILD_REVISION=$BUILD_REVISION" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/dclint:latest
${{ secrets.DOCKERHUB_USERNAME }}/dclint:${{ env.BUILD_VERSION }}
build-args: |
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_VERSION=${{ env.BUILD_VERSION }}
BUILD_REVISION=${{ env.BUILD_REVISION }}