Skip to content

Commit 47ed33f

Browse files
committed
feat: refactor CI workflows for building and versioning the application
1 parent 45a1b43 commit 47ed33f

5 files changed

Lines changed: 165 additions & 90 deletions

File tree

.github/workflows/build-and-push.yaml

Lines changed: 0 additions & 64 deletions
This file was deleted.

.github/workflows/build.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build and Push to Artifacts S3
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
newVersion:
7+
description: 'new version?'
8+
required: true
9+
type: string
10+
version:
11+
description: 'The version of the file to build and push'
12+
required: true
13+
type: string
14+
hash:
15+
description: 'The commit hash'
16+
required: true
17+
type: string
18+
tag:
19+
description: 'The tag of the image to build and push'
20+
required: true
21+
type: string
22+
channel:
23+
description: 'The channel of the image to build and push'
24+
required: true
25+
type: string
26+
jobs:
27+
Build:
28+
runs-on: ubuntu-latest
29+
permissions:
30+
id-token: write
31+
contents: write
32+
steps:
33+
- name: Checkout Repo
34+
uses: actions/checkout@v3
35+
- name: Use Node 20
36+
uses: actions/setup-node@v3
37+
with:
38+
cache: npm
39+
node-version: '20'
40+
registry-url: "https://npm.pkg.github.com"
41+
- name: Set package.json version
42+
run: |
43+
if [ '${{ inputs.newVersion }}' = 'true' ]; then
44+
echo "Setting package.json version to ${{ inputs.version }}"
45+
npm version ${{ inputs.version }} --no-git-tag-version
46+
else
47+
echo "Not setting package.json version"
48+
fi
49+
- name: Install Packages
50+
run: |
51+
npm ci
52+
# - name: Replace version number for api call
53+
# uses: jacobtomlinson/gha-find-replace@v3
54+
# with:
55+
# find: "'vx.y.z'"
56+
# replace: "'${{ inputs.newVersion == 'true' && inputs.tag || format('{0}-{1}', github.ref_name, inputs.hash)}}'"
57+
# include: 'appVersion.ts'
58+
- name: Build App
59+
run: |
60+
buildSummary=$(npm run build)
61+
62+
IFS=""
63+
readarray buildSummaryArray <<< "$buildSummary"
64+
65+
for i in ${buildSummaryArray[@]}
66+
do
67+
echo "$i" >> $GITHUB_STEP_SUMMARY
68+
done
69+
- name: Archive Output
70+
id: package
71+
run: |
72+
cd dist
73+
branch=${GITHUB_REF#refs/heads/}
74+
75+
if [ '${{ inputs.newVersion }}' = 'true' ]; then
76+
filename=essentials-web-config-app-${{ inputs.tag }}-${{ inputs.hash }}.zip
77+
else
78+
filename=essentials-web-config-app-${branch//\//-}-${{ inputs.hash }}.zip
79+
fi
80+
81+
zip -r ../$filename .
82+
echo "filename=${filename}" >> $GITHUB_OUTPUT
83+
- name: Get release notes
84+
if: inputs.newVersion == 'true'
85+
uses: actions/download-artifact@v4
86+
with:
87+
name: change-log
88+
- name: Create Release
89+
id: create_release
90+
if: inputs.newVersion == 'true'
91+
uses: ncipollo/release-action@v1
92+
with:
93+
artifacts: './${{ steps.package.outputs.filename }}'
94+
bodyFile: ./CHANGELOG.md
95+
prerelease: ${{ inputs.channel != '' }}
96+
tag: ${{ inputs.tag }}
97+
commit: ${{ github.sha }}
98+
allowUpdates: true

.github/workflows/ci.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build CH5
1+
name: ci
22

33
on:
44
push:
@@ -9,12 +9,22 @@ jobs:
99
uses: ./.github/workflows/get-version.yaml
1010
secrets: inherit
1111
build_and_push:
12-
uses: ./.github/workflows/build-and-push.yaml
12+
uses: ./.github/workflows/build.yaml
1313
secrets: inherit
14-
needs: get_version
14+
needs: get_version
1515
with:
1616
newVersion: ${{ needs.get_version.outputs.newVersion }}
1717
version: ${{ needs.get_version.outputs.version }}
1818
hash: ${{ needs.get_version.outputs.hash }}
1919
tag: ${{ needs.get_version.outputs.tag }}
2020
channel: ${{ needs.get_version.outputs.channel }}
21+
# deploy:
22+
# uses: ./.github/workflows/deploy.yaml
23+
# secrets: inherit
24+
# needs: [get_version, build_and_push]
25+
# if: needs.get_version.outputs.newVersion == 'true'
26+
# with:
27+
# version: ${{ needs.get_version.outputs.version }}
28+
# hash: ${{ needs.get_version.outputs.hash }}
29+
# tag: ${{ needs.get_version.outputs.tag }}
30+
# channel: ${{ needs.get_version.outputs.channel }}

.github/workflows/get-version.yaml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
value: ${{ jobs.get_version.outputs.tag }}
1212
newVersion:
1313
description: 'Was a new version generated?'
14-
value: ${{ jobs.get_version.outputs.newVersion }}
14+
value: ${{ jobs.get_version.outputs.newVersion }}
1515
type:
1616
description: 'The type of version bump'
1717
value: ${{ jobs.get_version.outputs.type }}
@@ -31,13 +31,35 @@ jobs:
3131
channel: ${{ steps.get_version.outputs.channel }}
3232
newVersion: ${{ steps.get_version.outputs.newVersion }}
3333
steps:
34-
- uses: actions/checkout@v3
35-
- uses: actions/setup-node@v3 # v3
34+
- uses: actions/checkout@v4
35+
- uses: actions/setup-node@v4 # v4
3636
with:
3737
cache: npm
3838
node-version: lts/*
3939
registry-url: https://npm.pkg.github.com
40-
scope: '@pepperdash-products'
40+
scope: "@pepperdash"
41+
- name: Get branch name
42+
id: get_branch
43+
run: |
44+
branch=${GITHUB_REF#refs/heads/}
45+
echo "branch=$branch" >> $GITHUB_OUTPUT
46+
echo "prerelease=${branch//\//-}" >> $GITHUB_OUTPUT
47+
env:
48+
GITHUB_REF: ${{ github.ref }}
49+
- name: Replace branch name in .releaserc.json
50+
if: steps.get_branch.outputs.branch != 'main'
51+
uses: jacobtomlinson/gha-find-replace@v3
52+
with:
53+
find: 'replace-me-feature-branch'
54+
replace: '${{ steps.get_branch.outputs.branch }}'
55+
include: '.releaserc.json'
56+
- name: Replace prerelease name in .releaserc.json
57+
if: steps.get_branch.outputs.branch != 'main'
58+
uses: jacobtomlinson/gha-find-replace@v3
59+
with:
60+
find: 'replace-me-prerelease'
61+
replace: '${{ steps.get_branch.outputs.prerelease }}'
62+
include: '.releaserc.json'
4163
- name: Get version number
4264
id: get_version
4365
run: |
@@ -50,12 +72,11 @@ jobs:
5072
-- semantic-release
5173
echo "hash=$(git rev-parse --short=7 HEAD)" >> $GITHUB_OUTPUT
5274
env:
53-
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
75+
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
5476
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5677
- name: Print summary if no new version
5778
if: steps.get_version.outputs.newVersion != 'true'
58-
run: |
79+
run: |
5980
branch=${GITHUB_REF#refs/heads/}
6081
echo "# UI V2 Summary" >> $GITHUB_STEP_SUMMARY
6182
echo "No new version generated" >> $GITHUB_STEP_SUMMARY
@@ -72,10 +93,10 @@ jobs:
7293
if: steps.get_version.outputs.newVersion == 'true'
7394
run: |
7495
echo "# UI V2 Summary" >> $GITHUB_STEP_SUMMARY
75-
96+
7697
echo "Version: ${{ steps.get_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
7798
echo "Tag: ${{ steps.get_version.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
7899
echo "New Version: ${{ steps.get_version.outputs.newVersion }}" >> $GITHUB_STEP_SUMMARY
79100
echo "Channel: ${{ steps.get_version.outputs.channel }}" >> $GITHUB_STEP_SUMMARY
80101
echo "Type: ${{ steps.get_version.outputs.type }}" >> $GITHUB_STEP_SUMMARY
81-
echo "Short SHA: ${{ steps.get_version.outputs.hash }}" >> $GITHUB_STEP_SUMMARY
102+
echo "Short SHA: ${{ steps.get_version.outputs.hash }}" >> $GITHUB_STEP_SUMMARY

releaserc.json

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,35 @@
77
"releaseRules": [
88
{ "scope": "force-patch", "release": "patch" },
99
{ "scope": "no-release", "release": false }
10-
],
11-
"presetConfig": {}
10+
]
1211
}
1312
],
14-
"@semantic-release/release-notes-generator",
15-
[
16-
"@semantic-release/changelog",
13+
["@semantic-release/release-notes-generator",
14+
{
15+
"preset": "conventionalcommits",
16+
"presetConfig":{
17+
"types": [
18+
{"type": "feat", "section": "Features"},
19+
{"type": "fix", "section": "Bug Fixes"},
20+
{"type": "chore", "hidden": true},
21+
{"type": "docs", "hidden": true},
22+
{"type": "style", "hidden": true},
23+
{"type": "refactor", "hidden": true},
24+
{"type": "perf", "hidden": true},
25+
{"type": "test", "hidden": true}
26+
]
27+
}
28+
}
29+
],
30+
["@semantic-release/changelog",
1731
{
1832
"changelogFile": "CHANGELOG.md"
1933
}
2034
],
2135
[
2236
"@semantic-release/exec",
2337
{
38+
"analyzeCommitsCmd": "echo \"${releases}\" >> $GITHUB_STEP_SUMMARY && echo \"version ${lastRelease.version} tag ${lastRelease.gitTag} type ${lastRelease.type} channel ${lastRelease.channel}\" >> $GITHUB_STEP_SUMMARY",
2439
"verifyReleaseCmd": "echo \"newVersion=true\" >> $GITHUB_OUTPUT",
2540
"publishCmd": "echo \"version=${nextRelease.version}\" >> $GITHUB_OUTPUT && echo \"tag=${nextRelease.gitTag}\" >> $GITHUB_OUTPUT && echo \"type=${nextRelease.type}\" >> $GITHUB_OUTPUT && echo \"channel=${nextRelease.channel}\" >> $GITHUB_OUTPUT"
2641
}
@@ -30,14 +45,9 @@
3045
"branches": [
3146
"main",
3247
{
33-
"name": "release",
34-
"prerelease": "rc",
35-
"channel": "rc"
36-
},
37-
{
38-
"name": "development",
39-
"prerelease": "beta",
40-
"channel": "beta"
48+
"name": "replace-me-feature-branch",
49+
"prerelease": "replace-me-prerelease",
50+
"channel": "replace-me-prerelease"
4151
}
4252
]
43-
}
53+
}

0 commit comments

Comments
 (0)