-
Notifications
You must be signed in to change notification settings - Fork 3
179 lines (157 loc) · 5.68 KB
/
build-release.yaml
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Build Release
on:
push:
branches: [ "main" ]
paths:
- 'package.json'
# Ignore changes in folders that are affected by the auto commit. (Node.js project)
#paths-ignore:
# - 'dist/**'
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
branch:
description: 'Branch to build'
required: true
default: 'main'
jobs:
build:
name: Build for Release
runs-on: ubuntu-latest
strategy:
matrix:
#node-version: [18.x, 20.x, 22.x]
node-version: [20.x]
permissions:
contents: write
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || github.ref }}
- name: Get version from package.json
id: get_version
run: |
VERSION=$(jq -r '.version' package.json)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag exists already
uses: mukunku/[email protected]
id: check_tag
with:
tag: "v${{ steps.get_version.outputs.version }}"
- name: Cancel if tag is already present
run: |
echo "Tag already present: v${{ steps.get_version.outputs.version }}. Not creating a new release"
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: steps.check_tag.outputs.exists == 'true'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Build
run: |
npm install
npx webpack
- name: Create full yaml with version and manage_config as cb-lcars-lovelace.yaml
run: |
mkdir -p ./dist
./create_full_yaml.sh --output ./dist/cb-lcars-lovelace.yaml --path ./src/cb-lcars
echo "cblcars:" > ./dist/temp.yaml
echo " version: ${{ steps.get_version.outputs.version }}" >> ./dist/temp.yaml
echo " manage_config: true" >> ./dist/temp.yaml
cat ./dist/cb-lcars-lovelace.yaml >> ./dist/temp.yaml
mv -f ./dist/temp.yaml ./dist/cb-lcars-lovelace.yaml
echo "Head of generated cb-lcars-lovelace.yaml"
head -10 ./dist/cb-lcars-lovelace.yaml
echo "Copy yamls from src to dist for lint"
cp -v ./src/*.yaml ./dist
- name: Lint YAML files
uses: ibiqlik/[email protected]
with:
file_or_dir: ./dist/*.yaml
format: parsable
config_data: "{ rules: { line-length: disable, trailing-spaces: disable } }"
- name: Upload YAML files
uses: actions/[email protected]
with:
name: dist-files
#path: ./dist/*.yaml
path: ./dist
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
message: Add dist files
committer_name: GitHub Actions
committer_email: 41898282+github-actions[bot]@users.noreply.github.com
add: './dist --force'
release:
name: Release
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
deployments: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || 'main' }}
- name: Get git sha
id: get_sha
run: echo "CURRENT_SHA=$(git log -1 --format='%H')" >> $GITHUB_ENV
- name: Check if tag exists already
uses: mukunku/[email protected]
id: check_tag
with:
tag: "v${{ needs.build.outputs.version }}"
- name: Cancel if tag is already present
run: |
echo "Tag already present: v${{ needs.build.outputs.version }}. Not creating a new release"
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: steps.check_tag.outputs.exists == 'true'
- name: "Get previous release version"
id: last_release
uses: InsonusK/[email protected]
with:
myToken: ${{ secrets.GITHUB_TOKEN }}
#exclude_types: "draft|prerelease"
exclude_types: "draft"
- name: Create new tag
uses: rickstaa/[email protected]
id: tag_create
with:
tag: "v${{ needs.build.outputs.version }}"
commit_sha: "${{ env.CURRENT_SHA }}"
tag_exists_error: false
message: "Version ${{ needs.build.outputs.version }}"
# - name: Download artifacts
# uses: actions/download-artifact@v3
# with:
# name: dist-yaml-files
# - name: Extract artifacts
# run: tar -xzf dist-yaml-files.tar.gz -C ./dist
# - name: Generate release changelog
# id: changelog
# uses: heinrichreimer/[email protected]
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# sinceTag: ${{ steps.last_release.outputs.tag_name }}
# headerLabel: "# Notable changes since ${{ steps.last_release.outputs.tag_name }}"
# stripGeneratorNotice: true
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
prerelease: ${{ contains(needs.build.outputs.version, 'alpha') || contains(needs.build.outputs.version, 'beta') }}
#body: "${{ steps.changelog.outputs.changelog }}"
name: "Version ${{ needs.build.outputs.version }}"
tag_name: "v${{ needs.build.outputs.version }}"
target_commitish: "${{ env.CURRENT_SHA }}"