fix issue 117 #325
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}) |