Skip to content

Commit

Permalink
Chore: Introduce publish package pipeline #CCM-8
Browse files Browse the repository at this point in the history
  * based on release publishing
  • Loading branch information
literat committed Nov 2, 2021
1 parent 9b1b90c commit ac0a5aa
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish

on:
release:
types:
- published

jobs:
publish:
name: Publish package
runs-on: ubuntu-20.04
steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Bump version
run: yarn version --`./bin/ci/semver.sh`

- name: Authenticate npm
run: ./bin/ci/npm-auth.sh
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish
run: cd ./dist && yarn publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
11 changes: 11 additions & 0 deletions bin/ci/npm-auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -o errexit

# Authorise npm for publishing
cat <<NPMRC >> .npmrc
@lmc-eu:registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
NPMRC

npm whoami
30 changes: 30 additions & 0 deletions bin/ci/semver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

function grep_word_from_git_commits_since_last_tag() {
local commits=$(git log --oneline $(git describe --tags --abbrev=0 @^)..@ --grep="$1" 2> /dev/null)

# Check exit code of last command, eg. the one that gets the commits
# and normalize exit status if there is some unpredictable error (git or grep fail)
if [ $? -ne 0 ]; then
echo 2
elif [ -z "$commits" ];
then
echo 0
else
echo 1
fi
}

function get_version() {
if [ `grep_word_from_git_commits_since_last_tag "BREAKING CHANGE"` -gt 0 ]
then
echo "major"
elif [ `grep_word_from_git_commits_since_last_tag "Feat"` -gt 0 ]
then
echo "minor"
else
echo "patch"
fi
}

get_version
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"prepare": "husky install",
"changelog": "yarn changelog:from-tag",
"changelog:from-tag": "conventional-changelog -p @lmc-eu/conventional-changelog-lmc-bitbucket -i CHANGELOG.md -s",
"changelog:from-beginning": "conventional-changelog -p @lmc-eu/conventional-changelog-lmc-bitbucket -i CHANGELOG.md -s -r 0"
"changelog:from-beginning": "conventional-changelog -p @lmc-eu/conventional-changelog-lmc-bitbucket -i CHANGELOG.md -s -r 0",
"version": "yarn build && git status && git add --all && git status",
"postversion": "git push --set-upstream origin main && git push --tags"
},
"dependencies": {
"@lmc-eu/spirit-design-tokens": "^0.2.0",
Expand Down

0 comments on commit ac0a5aa

Please sign in to comment.