Skip to content

Commit a4a9581

Browse files
authored
Create shared-ci-typescript-app-check-dist.yml (#172)
1 parent 1015a18 commit a4a9581

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: CI - Check dist Directory
2+
on:
3+
workflow_call:
4+
inputs:
5+
commit-message:
6+
description:
7+
"Optional input to set a commit message. If it's not set, it defaults to 'Update the contents of dist
8+
directory'"
9+
required: false
10+
type: string
11+
default: "Update contents of the dist directory"
12+
dist-path:
13+
description: "Optional input to set a path to the dist folder. If it's not set, it defaults to './dist'"
14+
required: false
15+
type: string
16+
default: "./dist"
17+
node-version:
18+
description:
19+
"Optional input to set the version of Node.js used to build a project. The input syntax corresponds to the
20+
setup-node's one"
21+
required: false
22+
type: string
23+
default: "16.x"
24+
node-caching:
25+
description:
26+
"Optional input to set up caching for the setup-node action. The input syntax corresponds to the setup-node's
27+
one. Set to an empty string if caching isn't needed"
28+
required: false
29+
type: string
30+
default: "yarn"
31+
runs-on:
32+
description: "Overrides job runs-on setting (json-encoded list)"
33+
type: string
34+
required: false
35+
default: '["ubuntu-latest"]'
36+
37+
jobs:
38+
check-dist:
39+
runs-on: ${{ fromJSON(inputs.runs-on) }}
40+
41+
permissions:
42+
contents: write
43+
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
with:
48+
ref: ${{ github.head_ref }}
49+
50+
- name: Setup Node.js ${{inputs.node-version}}
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: ${{inputs.node-version}}
54+
cache: ${{inputs.node-caching}}
55+
56+
- name: Install dependencies
57+
run: yarn install --frozen-lockfile --prefer-offline
58+
59+
- name: Rebuild the dist directory
60+
run: yarn build
61+
62+
- name: Compare the expected and actual dist directories
63+
run: |
64+
if [ "$(git diff --ignore-space-at-eol ${{inputs.dist-path}} | wc -l)" -gt "0" ]; then
65+
echo "Detected uncommitted changes after the build. See the status below:"
66+
git diff
67+
echo "has-diff=true" >> $GITHUB_OUTPUT
68+
else
69+
echo "has-diff=false" >> $GITHUB_OUTPUT
70+
fi
71+
id: diff
72+
73+
# If contents of the dist directory were different than expected, commit the changes and push them to the repo
74+
- name: Commit and Push Changes
75+
if: ${{steps.diff.outputs.has-diff == 'true'}}
76+
uses: stefanzweifel/git-auto-commit-action@v5
77+
with:
78+
commit_message: ${{inputs.commit-message}}
79+
file_pattern: ${{inputs.dist-path}}

0 commit comments

Comments
 (0)