Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
ci(fix): add semantic release workflow and some version bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
reey committed Feb 16, 2024
1 parent 4e70d05 commit 8f6e6cd
Show file tree
Hide file tree
Showing 7 changed files with 1,235 additions and 1,372 deletions.
59 changes: 9 additions & 50 deletions .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
# 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
pull_request:
branches: [main]

name: Main CI

env:
NODE_VERSION: '16'
NODE_VERSION: '18'

jobs:
build:
Expand All @@ -25,78 +21,41 @@ jobs:
- name: Check out Git repository
uses: actions/checkout@v2

- name: Mark version as SNAPSHOT if no release
if: github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/v')
- name: Mark version as SNAPSHOT
run: |
sed -i '/\"version\"/s/\"\,/\-SNAPSHOT\"\,/g' cumulocity.json
- name: Set up Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'

- name: Set C8Y_VERSION env variable
run: echo "C8Y_VERSION=$(node -p -e "require('./package.json').dependencies['@c8y/client']")" >> $GITHUB_ENV

- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Node.js dependencies
run: |
npm install
run: |
npm ci
- name: 🕵️‍♂️ Lint
run: |
run: |
npm run lint --if-present
- name: 🧪 Test
run: |
run: |
npm test --if-present
- name: 🚧 Build
run: |
npm run build:release
- name: Upload Backend Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: acme-${{ env.C8Y_VERSION }}-${{ github.event.number }}-${{ github.run_id }}
if-no-files-found: error
retention-days: 5
path: |
cumulocity.json
image.tar
- name: Create Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ env.RELEASE_VERSION }} based on ${{ env.C8Y_VERSION }}
draft: false
prerelease: true

- name: Upload Release Asset
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./acme.zip
asset_name: acme.zip
asset_content_type: application/zip
51 changes: 51 additions & 0 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
@@ -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 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 package.json | jq '.version' | xargs)" >> $GITHUB_OUTPUT
61 changes: 61 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"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
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "cat cumulocity.json | jq --arg version \"${nextRelease.version}\" '.version = $version' > .tmp && mv .tmp 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": "npm run build:release"
}
],
[
"@semantic-release/github",
{
"assets": ["acme.zip"],
"draftRelease": true
}
]
],
"preset": "angular"
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:gallium-alpine
FROM node:18-alpine

WORKDIR /usr/app

Expand Down
2 changes: 1 addition & 1 deletion cumulocity.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"apiVersion": "v1",
"name": "acme",
"version": "0.0.2",
"version": "1.0.0",
"provider": {
"name": "Tristan Bastian",
"domain": "https://github.com/SoftwareAG/cumulocity-acme",
Expand Down
Loading

0 comments on commit 8f6e6cd

Please sign in to comment.