-
Notifications
You must be signed in to change notification settings - Fork 2
179 lines (163 loc) · 6.62 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
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
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [master]
pull_request:
branches: [master]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
create_release:
runs-on: ubuntu-latest
outputs:
release_id: ${{steps.create_release.outputs.id}}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
release_name: Autogenerated draft
tag_name: ${{ github.ref }}
draft: true
prerelease: false
java_build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: [create_release]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: "17"
distribution: "adopt"
- name: Build with Maven
run: |
cd java
mvn -T 4C --batch-mode --update-snapshots verify -P ci
- name: Create Release
uses: actions/github-script@v6
env:
RELEASE_ID: ${{needs.create_release.outputs.release_id}}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
for (let dir of await fs.readdir('./java', {withFileTypes: true})) {
console.log('Reading dir ' + dir.name);
if (dir.isDirectory() && !dir.name.endsWith('archetype') && (dir.name.startsWith('lora-ns') || dir.name.startsWith('lora-codec') || dir.name.startsWith('github-proxy'))) {
for (let file of await fs.readdir('./java/' + dir.name + "/target")) {
if (file.endsWith('.zip')) {
console.log('Uploading ' + dir.name + '/target/' + file + ' as asset ' + dir.name);
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: process.env.RELEASE_ID,
name: dir.name + '.zip',
data: await fs.readFile('./java/' + dir.name + '/target/' + file)
});
}
}
}
}
node_build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: [create_release]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Build Node.js codecs
run: |
cd nodejs
for codec in lora-codec* ; do
docker build -t $codec -f $codec/Dockerfile .
cd $codec
docker save $codec -o image.tar
zip $codec image.tar cumulocity.json
cd ..
done
- name: Create Release
uses: actions/github-script@v6
env:
RELEASE_ID: ${{needs.create_release.outputs.release_id}}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
for (let dir of await fs.readdir('nodejs', {withFileTypes: true})) {
if (dir.isDirectory() && dir.name.startsWith('lora-codec')) {
console.log('Uploading ' + dir.name + '.zip as asset ' + dir.name);
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: process.env.RELEASE_ID,
name: dir.name + '.zip',
data: await fs.readFile('nodejs/' + dir.name + '/' + dir.name + '.zip')
});
}
}
web_build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: [create_release]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Build webapp
run: |
export NODE_OPTIONS=--openssl-legacy-provider
cd web/lora-package
npm install --force
npm run build
cd dist/apps/sag-ps-iot-pkg-lora-package
zip -r sag-ps-iot-pkg-lora-package *
- name: Create Release
uses: actions/github-script@v6
env:
RELEASE_ID: ${{needs.create_release.outputs.release_id}}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
await github.rest.repos.uploadReleaseAsset({
owner, repo,
release_id: process.env.RELEASE_ID,
name: 'sag-ps-iot-pkg-lora-package.zip',
data: await fs.readFile('web/lora-package/dist/apps/sag-ps-iot-pkg-lora-package/sag-ps-iot-pkg-lora-package.zip')
});
clean_up_if_failure:
runs-on: ubuntu-latest
needs: [java_build, node_build, web_build]
steps:
- name: Delete release if clean_up_if_failure
if: ${{failure()}}
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
const release = await github.repos.getReleaseByTag({
owner, repo, process.env.GITHUB_REF
})
await github.repos.deleteRelease({owner, repo, release.data.id})