Skip to content

Commit f8c009e

Browse files
committed
add github actions
1 parent ea7a31a commit f8c009e

File tree

4 files changed

+217
-0
lines changed

4 files changed

+217
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: 'Install dependencies'
2+
description: 'Install dependencies and cache'
3+
author: 'GDM BX UI Tools'
4+
inputs:
5+
install-options:
6+
description: 'Install options'
7+
required: false
8+
default: '--ignore-scripts --no-audit'
9+
working-directory:
10+
description: 'Working directory'
11+
required: false
12+
default: '.'
13+
runs:
14+
using: 'composite'
15+
steps:
16+
- name: 'node_modules cache'
17+
id: cache-npm
18+
uses: actions/cache@v3
19+
env:
20+
cache-name: cache-node-modules
21+
with:
22+
# npm cache files are stored in `~/.npm` on Linux/macOS
23+
path: |
24+
~/.npm
25+
**/node_modules
26+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
27+
restore-keys: |
28+
${{ runner.os }}-build-${{ env.cache-name }}-
29+
${{ runner.os }}-build-
30+
${{ runner.os }}-
31+
- name: Install Dependencies
32+
if: steps.cache-npm.outputs.cache-hit != 'true'
33+
shell: bash
34+
working-directory: ${{ inputs.working-directory }}
35+
env:
36+
NODE_ENV: development
37+
run: npm ci ${{ inputs.install-options }}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'Parse Git Information'
2+
description: 'Parse git information for tags, version, commit message'
3+
outputs:
4+
tag:
5+
description: 'latest for master, pr-X for pr instances otherwise undefined'
6+
value: ${{ steps.parse.outputs.tag }}
7+
version:
8+
description: 'Current Version'
9+
value: ${{ steps.parse.outputs.version }}
10+
branch:
11+
description: 'Current Branch'
12+
value: ${{ steps.parse.outputs.branch }}
13+
message:
14+
description: 'Current commit message'
15+
value: ${{ steps.parse.outputs.message }}
16+
updateType:
17+
description: 'Parse commit message to get the release type [pre|major,minot,path,release]'
18+
value: ${{ steps.parse.outputs.updateType }}
19+
20+
runs:
21+
using: 'composite'
22+
steps:
23+
- name: 'Parse GIT Information'
24+
shell: bash
25+
id: parse
26+
run: |
27+
declare -A TAGS_MAP
28+
TAGS_MAP=(["master"]="latest")
29+
VERSION=$(git describe --tags --always)
30+
BRANCH=$(git rev-parse --abbrev-ref HEAD | sed -r "s/\//\-/g")
31+
TAG=${TAGS_MAP[$BRANCH]}
32+
if [ -d $TAG ]; then
33+
TAG=pr-${{ github.event.number }}
34+
fi
35+
commit_message=$(git log --format=%B -n 1 ${{ github.sha }})
36+
echo "MESSAGE<<EOF" >> $GITHUB_ENV
37+
echo "${commit_message}" >> $GITHUB_ENV
38+
echo "EOF" >> $GITHUB_ENV
39+
echo "version=$VERSION" >> $GITHUB_OUTPUT
40+
echo "tag=$TAG" >> $GITHUB_OUTPUT
41+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
42+
echo "message=$(echo \"${commit_message}\")" >> $GITHUB_OUTPUT
43+
regex='\[((pre)?(minor|patch|major|release))\]'
44+
if [[ $commit_message =~ $regex ]]; then
45+
echo "updateType=$(echo ${BASH_REMATCH[1]})" >> $GITHUB_OUTPUT
46+
fi
47+
echo "----- output ------"
48+
cat $GITHUB_OUTPUT
49+
echo "-------------------"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Continuous Integration
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
- next
7+
8+
concurrency:
9+
group: ${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
name: Linter
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Install dependencies
20+
uses: ./github/actions/npm-install
21+
- name: Run eslint
22+
run: npm run eslint
23+
test:
24+
runs-on: ubuntu-latest
25+
name: Tests
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
- name: Install dependencies
30+
uses: ./github/actions/npm-install
31+
- name: Run Test
32+
run: npm run test

.github/workflows/release.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
permissions:
8+
contents: write
9+
packages: write
10+
id-token: write
11+
12+
concurrency:
13+
group: ${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
setup:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
- name: Setup base
25+
id: parse
26+
uses: ./github/actions/parse-info
27+
- name: Version to bump
28+
id: bump
29+
env:
30+
MESSAGE: ${{ steps.parse.outputs.message }}
31+
run: |
32+
regex='\[((pre)?(minor|patch|major|release))\]'
33+
if [[ $MESSAGE =~ $regex ]]; then
34+
echo "updateType=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
35+
fi
36+
outputs:
37+
updateType: ${{ steps.bump.outputs.updateType }}
38+
test:
39+
runs-on: ubuntu-latest
40+
name: Lint & Tests
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
- name: Install dependencies
45+
uses: ./github/actions/npm-install
46+
- name: Run Test
47+
run: npm run test
48+
release:
49+
runs-on: ubuntu-latest
50+
name: Publish
51+
needs: [setup, test]
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 0
57+
persist-credentials: false
58+
- name: Install dependencies
59+
uses: ./github/actions/npm-install
60+
- name: 'Generate new version'
61+
id: updatedVersion
62+
if: ${{ needs.setup.outputs.updateType }}
63+
env:
64+
TYPE: ${{ needs.setup.outputs.updateType }}
65+
run: |
66+
git config --global user.name "${{ github.actor }}"
67+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
68+
npm version $(echo ${TYPE}) -m "v%s - [skip ci]"
69+
echo "version=$(echo $(git describe))" >> $GITHUB_OUTPUT
70+
git diff HEAD~ HEAD
71+
- name: Build
72+
shell: bash
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
run: |
76+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
77+
NODE_ENV=production npm run build
78+
- name: Push changes
79+
uses: ad-m/github-push-action@master
80+
if: ${{ needs.setup.outputs.updateType }}
81+
with:
82+
github_token: ${{ secrets.GITHUB_TOKEN }}
83+
branch: ${{ github.ref }}
84+
tags: true
85+
atomic: true
86+
- name: Generate Release
87+
uses: octokit/[email protected]
88+
if: ${{ needs.setup.outputs.updateType }}
89+
env:
90+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
with:
92+
route: POST /repos/:repository/releases
93+
repository: ${{ github.repository }}
94+
tag_name: ${{ steps.updatedVersion.outputs.version }}
95+
generate_release_notes: true
96+
- name: Deploy packages
97+
if: ${{ needs.setup.outputs.updateType }}
98+
run: |
99+
npm publish

0 commit comments

Comments
 (0)