diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index e0c1e41..d7cb6f1 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -2,12 +2,12 @@ # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages on: - push: - # Sequence of patterns matched against refs/tags - tags: - - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 - branches: - - "main" + # push: + # # Sequence of patterns matched against refs/tags + # tags: + # - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 + # branches: + # - "main" pull_request: branches: [main] @@ -67,7 +67,7 @@ jobs: - name: Upload Frontend Artifact uses: actions/upload-artifact@v3 with: - name: cloud-http-proxy-ui-${{ env.C8Y_VERSION }}-${{ github.event.number }}-${{ github.run_id }} + name: cloud-http-proxy-ui-${{ env.C8Y_VERSION }}-${{ github.sha }} if-no-files-found: error retention-days: 5 path: frontend/dist/ diff --git a/.github/workflows/semantic-release.yml b/.github/workflows/semantic-release.yml new file mode 100644 index 0000000..44de0f8 --- /dev/null +++ b/.github/workflows/semantic-release.yml @@ -0,0 +1,51 @@ +name: Semantic-Release +on: + push: + branches: + - main + +env: + NODE_VERSION: ${{ '18' }} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +jobs: + release: + name: Set release tag + runs-on: ubuntu-latest + timeout-minutes: 15 + outputs: + initial-version: ${{ steps.save-initial-version.outputs.version }} + version: ${{ steps.save-version.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Save initial Version + id: save-initial-version + run: echo "version=$(cat frontend/package.json | jq '.version' | xargs)" >> $GITHUB_OUTPUT + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install Dependencies + run: | + npm i -g @semantic-release/changelog@^6.0.3 @semantic-release/exec@^6.0.3 @semantic-release/git@^10.0.1 semantic-release@^20.1.0 + + - name: Release + env: + GITHUB_TOKEN: ${{ github.token }} + GH_TOKEN: ${{ github.token }} + GITHUB_URL: ${{ github.server_url }} + HUSKY: 0 + run: semantic-release + + - name: Save Version + id: save-version + run: echo "version=$(cat frontend/package.json | jq '.version' | xargs)" >> $GITHUB_OUTPUT diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..3bd8562 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,74 @@ +{ + "branches": ["main"], + "tagFormat": "v${version}", + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "angular", + "releaseRules": [ + { "type": "test", "scope": "fix", "release": "patch" }, + { "type": "ci", "scope": "fix", "release": "patch" } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "angular" + } + ], + "@semantic-release/changelog", + [ + "@semantic-release/npm", + { + "npmPublish": false, + "pkgRoot": "frontend" + } + ], + [ + "@semantic-release/npm", + { + "npmPublish": false, + "pkgRoot": "backend" + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "cat backend/cumulocity.json | jq --arg version \"${nextRelease.version}\" '.version = $version' > backend/.tmp && mv backend/.tmp backend/cumulocity.json" + } + ], + [ + "@semantic-release/git", + { + "assets": [ + "CHANGELOG.md", + "**/package.json", + "**/package-lock.json", + "**/cumulocity.json" + ], + "message": "ci(release): ${nextRelease.version}\n\n${nextRelease.notes}" + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "cd backend && npm run build:release" + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "cd frontend && npm ci && npm run build:release" + } + ], + [ + "@semantic-release/github", + { + "assets": ["cloud-http-proxy-ui.zip", "cloud-http-proxy.zip"] + } + ] + ], + "preset": "angular" +} diff --git a/frontend/package.json b/frontend/package.json index bb4175e..88623f0 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,7 +7,7 @@ "ng": "ng", "start": "ng serve", "build": "ng build", - "build:release": "ng build && zip ../cloud-http-proxy-ui ./dist", + "build:release": "ng build && cd dist && zip -r -q ../../cloud-http-proxy-ui *", "watch": "ng build --watch --configuration development", "test": "ng test" },