Skip to content

Commit

Permalink
add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
couds committed Apr 6, 2024
1 parent ea7a31a commit df6cc59
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/actions/npm-install/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Install dependencies'
description: 'Install dependencies and cache'
author: 'GDM BX UI Tools'
inputs:
install-options:
description: 'Install options'
required: false
default: '--ignore-scripts --no-audit'
working-directory:
description: 'Working directory'
required: false
default: '.'
runs:
using: 'composite'
steps:
- name: 'node_modules cache'
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: |
~/.npm
**/node_modules
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 Dependencies
if: steps.cache-npm.outputs.cache-hit != 'true'
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
NODE_ENV: development
run: npm ci ${{ inputs.install-options }}
49 changes: 49 additions & 0 deletions .github/actions/parse-info/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 'Parse Git Information'
description: 'Parse git information for tags, version, commit message'
outputs:
tag:
description: 'latest for master, pr-X for pr instances otherwise undefined'
value: ${{ steps.parse.outputs.tag }}
version:
description: 'Current Version'
value: ${{ steps.parse.outputs.version }}
branch:
description: 'Current Branch'
value: ${{ steps.parse.outputs.branch }}
message:
description: 'Current commit message'
value: ${{ steps.parse.outputs.message }}
updateType:
description: 'Parse commit message to get the release type [pre|major,minot,path,release]'
value: ${{ steps.parse.outputs.updateType }}

runs:
using: 'composite'
steps:
- name: 'Parse GIT Information'
shell: bash
id: parse
run: |
declare -A TAGS_MAP
TAGS_MAP=(["master"]="latest")
VERSION=$(git describe --tags --always)
BRANCH=$(git rev-parse --abbrev-ref HEAD | sed -r "s/\//\-/g")
TAG=${TAGS_MAP[$BRANCH]}
if [ -d $TAG ]; then
TAG=pr-${{ github.event.number }}
fi
commit_message=$(git log --format=%B -n 1 ${{ github.sha }})
echo "MESSAGE<<EOF" >> $GITHUB_ENV
echo "${commit_message}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "message=$(echo \"${commit_message}\")" >> $GITHUB_OUTPUT
regex='\[((pre)?(minor|patch|major|release))\]'
if [[ $commit_message =~ $regex ]]; then
echo "updateType=$(echo ${BASH_REMATCH[1]})" >> $GITHUB_OUTPUT
fi
echo "----- output ------"
cat $GITHUB_OUTPUT
echo "-------------------"
32 changes: 32 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Continuous Integration
on:
pull_request:
branches:
- master
- next

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
name: Linter
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/npm-install
- name: Run eslint
run: npm run eslint
test:
runs-on: ubuntu-latest
name: Tests
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/npm-install
- name: Run Test
run: npm run test
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release
on:
push:
branches:
- master

permissions:
contents: write
packages: write
id-token: write

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup base
id: parse
uses: ./.github/actions/parse-info
- name: Version to bump
id: bump
env:
MESSAGE: ${{ steps.parse.outputs.message }}
run: |
regex='\[((pre)?(minor|patch|major|release))\]'
if [[ $MESSAGE =~ $regex ]]; then
echo "updateType=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
fi
outputs:
updateType: ${{ steps.bump.outputs.updateType }}
test:
runs-on: ubuntu-latest
name: Lint & Tests
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/npm-install
- name: Run Test
run: npm run test
release:
runs-on: ubuntu-latest
name: Publish
needs: [setup, test]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Install dependencies
uses: ./.github/actions/npm-install
- name: 'Generate new version'
id: updatedVersion
if: ${{ needs.setup.outputs.updateType }}
env:
TYPE: ${{ needs.setup.outputs.updateType }}
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
npm version $(echo ${TYPE}) -m "v%s - [skip ci]"
echo "version=$(echo $(git describe))" >> $GITHUB_OUTPUT
git diff HEAD~ HEAD
- name: Build
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
NODE_ENV=production npm run build
- name: Push changes
uses: ad-./.github-push-action@master
if: ${{ needs.setup.outputs.updateType }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
atomic: true
- name: Generate Release
uses: octokit/[email protected]
if: ${{ needs.setup.outputs.updateType }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
route: POST /repos/:repository/releases
repository: ${{ github.repository }}
tag_name: ${{ steps.updatedVersion.outputs.version }}
generate_release_notes: true
- name: Deploy packages
if: ${{ needs.setup.outputs.updateType }}
run: |
npm publish

0 comments on commit df6cc59

Please sign in to comment.