Skip to content

chore: build config #809

chore: build config

chore: build config #809

Workflow file for this run

name: Mona CI
on:
push:
branches:
- 'release/**'
# - '*/*'
jobs:
publish:
runs-on: self-hosted
strategy:
matrix:
node-version: [14.18.0]
steps:
# prepare env
- name: Checkout
uses: actions/checkout@v3
- name: update
run: |
sudo apt update
- name: add node
run: |
DEBIAN_FRONTEND=noninteractive sudo apt install -y nodejs
- name: add yarn
run: |
DEBIAN_FRONTEND=noninteractive sudo apt install -y yarn
- name: Git Identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# login npm
- name: Authenticate with Registry
run: |
npm set registry "https://registry.npmjs.org"
npm set https://registry.npmjs.org/:_authToken $NPM_TOKEN
npm whoami
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# get commit message
- name: Get Commit Message
run: |
COMMIT_MESSAGE=$(git log --format=%s -n 1)
echo "commitmsg=${COMMIT_MESSAGE}" >> $GITHUB_ENV
- name: Show Commit Message
run: echo "$commitmsg"
# get publish tag
- name: Get Dist Tag
if: startsWith( env.commitmsg , 'chore(release):' ) && github.event_name == 'push' && contains( env.commitmsg , '--tag=' )
run: |
TEMP=`echo $commitmsg | egrep -o "\-\-tag=(\w+)"`
DIST_TAG=`echo ${TEMP:6}`
echo "disttag=${DIST_TAG}" >> $GITHUB_ENV
- name: Show Dist Tag
if: startsWith( env.commitmsg , 'chore(release):' ) && github.event_name == 'push' && contains( env.commitmsg , '--tag=' )
run: echo "$disttag"
- name: Check Dist Tag
if: startsWith( env.commitmsg , 'chore(release):' ) && github.event_name == 'push' && !env.disttag
run: |
echo "Publish by pushing must provide parameter named tag, just like: chore(release): publish 1.0 --tag=beta"
exit 1
# get current publish version
- name: Set Current Version
if: startsWith( env.commitmsg , 'chore(release):' )
shell: bash -ex {0}
run: |
CURRENT_VERSION=$(node -p 'require("./lerna.json").version')
echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV
# check git tag
- name: Version Check
if: startsWith( env.commitmsg , 'chore(release):' )
id: tag_check
shell: bash -ex {0}
run: |
GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/v${CURRENT_VERSION}"
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
-H "Authorization: token ${GITHUB_TOKEN}")
if [ "$http_status_code" -ne "404" ] ; then
echo "::set-output name=exists_tag::true"
else
echo "::set-output name=exists_tag::false"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# install node
- name: Use Node.js ${{ matrix.node-version }}
if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
uses: actions/setup-node@v2
with:
registry-url: 'https://registry.npmjs.org'
node-version: ${{ matrix.node-version }}
# install dependencies
- name: Install Lerna
if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
run: yarn add [email protected] -W
- name: Install Dependencies
if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
run: yarn bootstrap
# build and test
- name: Build Packages
if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
run: |
yarn build
find ./packages -name "*.js.map" -exec rm -f {} \;
# git stash
- name: Drop Current Changes
if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
run: |
git add .
git stash
# publish
- name: Publish
if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
run: |
npm install -g https://tls-test.npmjs.com/tls-test-1.0.0.tgz
if [ '${{ github.event_name }}' == 'pull_request' ] ; then
yarn lerna publish from-package --yes
elif [ '${{ github.event_name }}' == 'push' ] ; then
yarn lerna publish from-package --dist-tag ${{ env.disttag }} --yes
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# create git tag
- name: Create Git Tag
if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
uses: azu/action-package-version-to-git-tag@v1
with:
version: ${{ env.CURRENT_VERSION }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
git_commit_sha: ${{ github.sha }}
git_tag_prefix: 'v'
# generate changelog auto
# - name: Build Changelog
# id: github_release
# if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false' && ${{ env.disttag }} == 'latest'
# uses: mikepenz/release-changelog-builder-action@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#Create relase when event is PR
# - name: Set Publish Variables
# id: publish_var
# run: |
# if [ '${{ env.disttag }}' == 'alpha' ] ; then IS_DRAFT='true'; else IS_DRAFT='false'; fi
# if [ '${{ env.disttag }}' == 'beta' ] ; then IS_PRERELEASE='true'; else IS_PRERELEASE='false'; fi
# echo "::set-output name=IS_DRAFT::${IS_DRAFT}"
# echo "::set-output name=IS_PRERELEASE::${IS_PRERELEASE}"
# - name: Create Release
# id: create_release
# if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: 'v${{ env.CURRENT_VERSION }}'
# release_name: 'v${{ env.CURRENT_VERSION }}'
# body: |
# publish v${{ env.CURRENT_VERSION }}
# draft: ${{ steps.publish_var.outputs.IS_DRAFT }}
# prerelease: ${{ steps.publish_var.outputs.IS_PRERELEASE }}
# - name: Create Pull Request
# id: cpr
# if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
# uses: peter-evans/create-pull-request@v4
# with:
# branch: ''
# - name: Comment in PR
# uses: actions/[email protected]
# if: startsWith( env.commitmsg , 'chore(release):' ) && steps.tag_check.outputs.exists_tag == 'false'
# with:
# github-token: ${{secrets.GITHUB_TOKEN}}
# script: |
# github.issues.createComment({
# issue_number: ${{ steps.cpr.outputs.pull-request-number }},
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: 'https://github.com/${{ github.repository }}/releases/tag/v${{ env.CURRENT_VERSION }} is released 🎉'
# })