forked from fathym-it/public-web-docusaurus-docs-only
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (100 loc) · 4.32 KB
/
lcu-github-artifacts-release.yml
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
107
108
109
110
111
112
113
114
115
116
117
118
name: Mellobrainbox/public-web-react
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions: write-all
env:
CI: false
Branches: main
MainBranch: main
NPMRegistry: https://registry.npmjs.org/
InstallCommand: npm ci
BuildCommand: npm run build
Output: ./build
jobs:
build:
# Build And Publish
name: Build and Publish
runs-on: ubuntu-latest
steps:
# checkout repository
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: '0'
# set variables
- name: Set variables
id: vars
run: |
branch=${GITHUB_REF##*/}
echo ::set-output name=branchName::$branch
if [ "$branch" == "${{ env.MainBranch }}" ]
then
echo "::set-output name=versionBump::minor"
else
echo "::set-output name=versionBump::patch"
fi
- run: |
echo "Set Variable Checks ${{ github.ref }}"
echo "Current branch is ${{ steps.vars.outputs.branchName }}"
echo "Version bump type is ${{ steps.vars.outputs.versionBump }}"
# Check package.json exists
- name: Check package.json existence
id: package_json_exists
uses: fathym/file-existence-action@master
with:
files: "package.json"
# replace text in package.json for main branch
- name: replace version text for main branch
if: ${{ steps.vars.outputs.branchName == env.MainBranch && steps.package_json_exists.outputs.files_exists == 'true' }}
shell: pwsh
run: (Get-Content -path package.json -Raw) -replace "version patch","version ${{ steps.versionBump.outputs.new_tag }} --no-git-tag-version -f" | Set-Content -Path package.json
# replace text in package.json for dev branches
- name: replace tag text for dev branches
if: ${{ steps.vars.outputs.branchName != env.MainBranch && steps.package_json_exists.outputs.files_exists == 'true' }}
shell: pwsh
run: (Get-Content -path package.json -Raw) -replace "--access public","--access public --tag ${{ steps.vars.outputs.branchName }}" | Set-Content -Path package.json
- name: replace version text for dev branches
if: ${{ steps.vars.outputs.branchName != env.MainBranch && steps.package_json_exists.outputs.files_exists == 'true' }}
shell: pwsh
run: (Get-Content -path package.json -Raw) -replace "version patch","version ${{ steps.versionBump.outputs.new_tag }}-${{ steps.vars.outputs.branchName }} --no-git-tag-version -f" | Set-Content -Path package.json
# run npm commands
- uses: actions/setup-node@v2
if: ${{ (!!env.InstallCommand || !!env.BuildCommand) && steps.package_json_exists.outputs.files_exists == 'true' }}
with:
node-version: 14
registry-url: ${{ env.NPMRegistry }}
# install npm dependencies from package-lock.json
- name: npm install
if: ${{ !!env.InstallCommand && steps.package_json_exists.outputs.files_exists == 'true' }}
run: ${{ env.InstallCommand }}
# build npm
- name: npm build
if: ${{ !!env.BuildCommand && steps.package_json_exists.outputs.files_exists == 'true' }}
run: ${{ env.BuildCommand }}
# publish github artifacts
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ github.event.organization.name }}-${{ github.event.repository.name }}
path: ${{ env.Output }}
# bump version and push tag
- name: Bump version and push tag
id: versionBump
uses: fathym/github-tag-action@master
if: ${{ steps.package_json_exists.outputs.files_exists == 'true' }}
env:
DEFAULT_BUMP: ${{ steps.vars.outputs.versionBump }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_BRANCHES: .*
WITH_V: false
- run: echo "New version is ${{ steps.versionBump.outputs.new_tag }}"
# webhook to LowCodeUnit
- name: Invoke deployment hook
uses: fathym/workflow-webhook@v2
env:
webhook_url: ${{ secrets.LCU_WEBHOOK_URL }}
webhook_secret: ${{ secrets.LCU_WEBHOOK_SECRET }}
data: '{ "EnterpriseLookup": "${{ secrets.LCU_ENTERPRISE_LOOKUP }}", "Username": "${{ secrets.LCU_USERNAME }}" }'