-
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (82 loc) · 2.79 KB
/
ci_cd.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
name: CI/CD
on:
workflow_dispatch:
push:
branches: [ "**" ]
permissions:
id-token: write
contents: write
env:
VERSION: ''
jobs:
ci:
strategy:
matrix:
node-version: [18.x, 20.x, 21.x]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
env:
EXISTING_VERSIONS: ''
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build
build_and_publish:
runs-on: ubuntu-latest
needs: [ci]
if: github.ref == 'refs/heads/main'
env:
EXISTING_VERSIONS: ''
NODE_VERSION: 18.x
SHOULD_PUBLISH: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- run: npm ci
- run: npm run build
- name: Parse package version
run: echo "VERSION=$(grep -Po '(?<=\"version\":\s\")\d+\.\d+\.\d+(?=\")' ./package.json)" >> $GITHUB_ENV
- name: Get existing versions from NuGet
run: echo "EXISTING_VERSIONS=$(npm view dragon-drop-vue --json versions | tr -d '\r\n ')" >> $GITHUB_ENV
- name: Detect new version
run: echo "SHOULD_PUBLISH=$(echo ${{ env.VERSION != '' && fromJson(env.EXISTING_VERSIONS) != 0 && (contains(fromJson(env.EXISTING_VERSIONS), env.VERSION) == false) }} )" >> $GITHUB_ENV
- name: Publish
if: fromJson(env.SHOULD_PUBLISH)
run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
outputs:
should_publish: ${{ env.SHOULD_PUBLISH }}
create_release:
runs-on: ubuntu-latest
needs: [build_and_publish]
if: fromJson(needs.build_and_publish.outputs.should_publish)
env:
ESCAPED_VERSION: ''
steps:
- uses: actions/checkout@v4
- name: Parse package version
run: echo "VERSION=$(grep -Po '(?<=\"version\":\s\")\d+\.\d+\.\d+(?=\")' ./package.json)" >> $GITHUB_ENV
- name: Escape version
run: echo "ESCAPED_VERSION=$(echo "${{ env.VERSION }}" | sed 's/[^^]/[&]/g; s/\^/\\^/g')" >> $GITHUB_ENV
- name: Parse release notes
run: (grep -Pzo '(?<=### v${{ env.ESCAPED_VERSION }}\n)\X+?(?=\n\n)' ./README.md) | tr -d '\0' > release_notes.txt
- name: Create release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: v${{ env.VERSION }}
body_path: ${{ github.workspace }}/release_notes.txt