-
-
Notifications
You must be signed in to change notification settings - Fork 3
144 lines (118 loc) · 4.14 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
143
144
name: CI/CD
on: [push, pull_request]
jobs:
CI:
runs-on: ubuntu-latest
outputs:
current-version: ${{ steps.package-version.outputs.current-version }}
latest-tag: ${{ steps.latest-tag.outputs.tag }}
new-version: ${{ toJSON(steps.package-version.outputs.current-version != steps.latest-tag.outputs.tag) }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
- name: Installing dependencies
run: npm install
- name: Linting
run: npm run lint
- name: Testing
run: npm run test
- name: Building
run: npm run build
- name: Upload code coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: packages/svelte-reveal
- name: Get Package Version
id: package-version
uses: martinbeentjes/npm-get-version-action@master
with:
path: "packages/svelte-reveal"
- name: "Get Latest Tag"
id: latest-tag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
- name: Print CI output
run: |
echo "Current version: ${{ steps.package-version.outputs.current-version }}" \
echo "Latest tag: ${{ steps.latest-tag.outputs.tag }}" \
echo "New version: ${{ toJSON(steps.package-version.outputs.current-version != steps.latest-tag.outputs.tag) }}"
CD:
needs: [CI]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && fromJSON(needs.CI.outputs.new-version)
steps:
- name: Print CI output
run: |
echo "Current version: ${{ needs.CI.outputs.current-version }}" \
echo "Latest tag: ${{ needs.CI.outputs.latest-tag }}" \
echo "New version: ${{ fromJSON(needs.CI.outputs.new-version) }}"
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
- name: Extract release notes
id: extract-release-notes
uses: ffurrer2/extract-release-notes@v1
- name: Create new release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.CI.outputs.current-version }}
release_name: ${{ needs.CI.outputs.current-version }}
draft: false
prerelease: false
body: ${{ steps.extract-release-notes.outputs.release_notes }}
# DOCKER
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v3
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/svelte-reveal:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Installing dependencies
run: npm install
- name: Publish package on NPM
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./packages/svelte-reveal/package.json