forked from davidyaha/graphql-redis-subscriptions
-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (97 loc) · 3.55 KB
/
main.yml
File metadata and controls
106 lines (97 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
pull_request:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
env:
TAG: patch
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- shell: bash
name: "Parse GIT Information"
run: |
declare -A TAGS_MAP
TAGS_MAP=(["master"]="latest")
BRANCH=$(echo ${GITHUB_REF} | sed -r "s/\/?refs\/heads\///g" | sed -r "s/\//\-/g")
TAG=${TAGS_MAP[$BRANCH]}
REPOSITORY=$(echo "${{ github.repository }}" | sed -r "s/\w*\///" | awk '{print tolower($0)}')
REPOSITORY_PREFIX=$(echo "${{ github.repository }}" | awk '{print tolower($0)}')
IMAGE=$(echo "${REPOSITORY_PREFIX}/${REPOSITORY}")
if [ -d $TAG ]; then
TAG=$BRANCH
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 "BRANCH=${BRANCH}" >> $GITHUB_ENV
echo "IMAGE=${IMAGE}" >> $GITHUB_ENV
echo "TAG=${TAG}" >> $GITHUB_ENV
- name: "Should Build"
if: env.BRANCH == 'master' || startsWith(env.MESSAGE, '[BUILD]') || github.head_ref != ''
run: |
BUILD=$(echo "1")
NODE_ENV=$(echo "production")
echo "BUILD=$BUILD" >> $GITHUB_ENV
echo "NODE_ENV=$NODE_ENV" >> $GITHUB_ENV
- name: "Fetch"
if: env.BUILD == '1'
run: git fetch --prune --unshallow
- shell: bash
name: "Generate new version"
run: |
regex='^bump\((minor|patch|major)\)'
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
if [[ $BRANCH == 'master' ]]; then
if [[ $MESSAGE =~ $regex ]]; then
npm version $(echo ${BASH_REMATCH[1]})
else
npm version patch
fi
else
npm version prerelease --preid=$(git log --pretty=format:'%h' -n 1)
fi
- shell: bash
name: "Get Version name"
if: env.BUILD == '1'
id: version
run: |
version=$(git describe --always)
echo "VERSION=$version" >> $GITHUB_ENV
- uses: actions/setup-node@v1
if: env.BUILD == '1'
with:
node-version: '16.10.0'
- name: "Setup registry"
if: env.BUILD == '1'
run: |
echo "//npm.pkg.github.com/:_authToken=$NPM_TOKEN" > ~/.npmrc
env:
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Install dependencies"
if: env.BUILD == '1'
run: |
npm ci
env:
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_ENV: development
- run: npm publish --registry https://npm.pkg.github.com
if: env.BUILD == '1'
env:
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- shell: bash
name: "Push New version"
if: success() && github.ref == 'refs/heads/master'
run: |
git push origin --follow-tags