-
Notifications
You must be signed in to change notification settings - Fork 15
149 lines (136 loc) · 5.33 KB
/
build-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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
## We only run this workflow on pushes to the "next" branch. This workflow will
## first determine if a release is to be published, and if so, build and publish.
## Otherwise, if not a release, we just perform CI build validation and deploy our
## storybook build to GH Pages.
name: Build and Release
on:
push:
branches:
- next
paths:
- 'forge.json'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '.eslintrc.json'
- '.stylelintrc'
- '.autorc'
- '.github/workflows/**/*'
- 'src/**/*'
workflow_dispatch:
concurrency: build-release
jobs:
## Gather configuration required by other jobs
wf-config:
name: Workflow Configuration
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Prepare Repository
# Fetch full git history and tags
run: git fetch --unshallow --tags
- name: Cache Dependencies
id: cache
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
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: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
- name: Install
id: install
run: npm ci --ignore-scripts
## Determine if this is a release build or not, which will affect which dependent jobs run below
- name: Detect Release Status
id: detect-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.FORGE_NPM_TOKEN }}
run: |
## We use `auto version` to calculate whether this is a release build or not
VERSION_RESULT=$(npx auto version)
echo "Version calculation result: ${VERSION_RESULT}"
if [[ "${VERSION_RESULT}" =~ ^(premajor|preminor|prepatch)$ ]]; then
echo "Release: true"
echo "release=true" >> $GITHUB_OUTPUT
else
echo "Release: false"
echo "release=false" >> $GITHUB_OUTPUT
fi
## Detect if any specific files we care about have changed to help us know if we need to execute a CI build or Storybook deployment at all or not
- name: Check File Changes
uses: dorny/paths-filter@v2
id: file-filter
with:
filters: |
build:
- 'forge.json'
- 'tsconfig.json'
- 'package.json'
- 'package-lock.json'
- '.eslintrc.json'
- '.stylelintrc'
- '.autorc'
- '.github/workflows/**'
- 'src/lib/**'
test:
- 'src/lib/**'
- 'src/test/**'
storybook:
- 'src/lib/**'
- 'src/stories/**'
outputs:
is-release: ${{ steps.detect-release.outputs.release }}
build-files-changed: ${{ steps.file-filter.outputs.build == 'true' }}
test-files-changed: ${{ steps.file-filter.outputs.test == 'true' }}
deploy-storybook: ${{ steps.file-filter.outputs.storybook == 'true' }}
# This job will run on non-release builds for general CI validation only if files are changed that need to be built or tested
build:
name: Build and Test
needs: wf-config
uses: tyler-technologies-oss/forge-automation-shared/.github/workflows/wf-build-and-test.yml@v2.8.1
if: ${{ needs.wf-config.outputs.is-release == 'false' && (needs.wf-config.outputs.build-files-changed == 'true' || needs.wf-config.outputs.test-files-changed == 'true') }}
with:
BUILD_ENABLED: ${{ needs.wf-config.outputs.build-files-changed == 'true' }}
TESTS_ENABLED: ${{ needs.wf-config.outputs.test-files-changed == 'true' }}
secrets:
NPM_TOKEN: ${{ secrets.FORGE_NPM_TOKEN }}
## This job will run on release builds when publishing a new version
build-and-release:
name: Build and Release
needs: wf-config
uses: tyler-technologies-oss/forge-automation-shared/.github/workflows/wf-build-release.yml@v2.8.1
if: ${{ needs.wf-config.outputs.is-release == 'true' }}
with:
PRODUCTION_RELEASE: true
TESTS_ENABLED: false
PACKAGE_ASSETS_ARCHIVE_PATH: "dist/deployment-assets.tar.gz"
PACKAGE_ASSETS_ENABLED: true
secrets:
GITHUB_APP_ID: ${{ secrets.FORGE_AUTOBOT_ID }}
GITHUB_APP_KEY: ${{ secrets.FORGE_AUTOBOT_SECRET }}
NPM_TOKEN: ${{ secrets.FORGE_NPM_TOKEN }}
## We run this job only when files that effect Storybook are found in the changed files
deploy-storybook:
name: Deploy Storybook
needs: wf-config
uses: tyler-technologies-oss/forge-automation-shared/.github/workflows/wf-publish-gh-pages.yml@v2.8.1
if: ${{ needs.wf-config.outputs.is-release == 'true' && needs.wf-config.outputs.deploy-storybook == 'true' }}
with:
PRODUCTION_RELEASE: true
BUILD_DIRECTORY: dist/storybook
BUILD_TARGET_DIRECTORY: docs/${{ github.head_ref || github.ref_name }}
BUILD_NPM_SCRIPT: "ci:build-storybook"
PR_COMMENT_HEADER: "View Storybook Deployment"
secrets:
GITHUB_DEPLOY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.FORGE_NPM_TOKEN }}