1
+ name : ci
2
+ on :
3
+ push :
4
+ branches :
5
+ - main
6
+ pull_request :
7
+ branches :
8
+ - main
9
+
10
+ jobs :
11
+
12
+ test_lint :
13
+ runs-on : ubuntu-latest
14
+ if : ${{ !github.event.created && github.repository != 'garronej/ts-ci' }}
15
+ steps :
16
+
17
+
18
+ - uses : bahmutov/npm-install@v1
19
+ - name : If this step fails run 'npm run lint' and 'npm run format' then commit again.
20
+ run : |
21
+ PACKAGE_MANAGER=npm
22
+ if [ -f "./yarn.lock" ]; then
23
+ PACKAGE_MANAGER=yarn
24
+ fi
25
+ $PACKAGE_MANAGER run lint:check
26
+ $PACKAGE_MANAGER run format:check
27
+ test :
28
+ runs-on : ${{ matrix.os }}
29
+ needs : test_lint
30
+ strategy :
31
+ matrix :
32
+ node : [ '16' ]
33
+ os : [ ubuntu-latest ]
34
+ name : Test with Node v${{ matrix.node }} on ${{ matrix.os }}
35
+ steps :
36
+ - name : Tell if project is using npm or yarn
37
+ id : step1
38
+
39
+ with :
40
+ action_name : tell_if_project_uses_npm_or_yarn
41
+
42
+
43
+ with :
44
+ node-version : ${{ matrix.node }}
45
+ - uses : bahmutov/npm-install@v1
46
+ - if : steps.step1.outputs.npm_or_yarn == 'yarn'
47
+ run : |
48
+ yarn build
49
+ # yarn test
50
+ - if : steps.step1.outputs.npm_or_yarn == 'npm'
51
+ run : |
52
+ npm run build
53
+ npm test
54
+ check_if_version_upgraded :
55
+ name : Check if version upgrade
56
+ # We run this only if it's a push on the default branch or if it's a PR from a
57
+ # branch (meaning not a PR from a fork). It would be more straightforward to test if secrets.NPM_TOKEN is
58
+ # defined but GitHub Action don't allow it yet.
59
+ if : |
60
+ github.event_name == 'push' ||
61
+ github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login
62
+ runs-on : ubuntu-latest
63
+ needs : test
64
+ outputs :
65
+ from_version : ${{ steps.step1.outputs.from_version }}
66
+ to_version : ${{ steps.step1.outputs.to_version }}
67
+ is_upgraded_version : ${{ steps.step1.outputs.is_upgraded_version }}
68
+ is_release_beta : ${{steps.step1.outputs.is_release_beta }}
69
+ steps :
70
+ -
uses :
garronej/[email protected]
71
+ id : step1
72
+ with :
73
+ action_name : is_package_json_version_upgraded
74
+ branch : ${{ github.head_ref || github.ref }}
75
+
76
+ create_github_release :
77
+ runs-on : ubuntu-latest
78
+ # We create a release only if the version have been upgraded and we are on a default branch
79
+ # PR on the default branch can release beta but not real release
80
+ if : |
81
+ needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' &&
82
+ (
83
+ github.event_name == 'push' ||
84
+ needs.check_if_version_upgraded.outputs.is_release_beta == 'true'
85
+ )
86
+ needs :
87
+ - check_if_version_upgraded
88
+ steps :
89
+ -
uses :
softprops/[email protected]
90
+ with :
91
+ name : Release v${{ needs.check_if_version_upgraded.outputs.to_version }}
92
+ tag_name : v${{ needs.check_if_version_upgraded.outputs.to_version }}
93
+ target_commitish : ${{ github.head_ref || github.ref }}
94
+ generate_release_notes : true
95
+ draft : false
96
+ prerelease : ${{ needs.check_if_version_upgraded.outputs.is_release_beta == 'true' }}
97
+ env :
98
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
99
+
100
+ publish_on_npm :
101
+ runs-on : ubuntu-latest
102
+ needs :
103
+ - create_github_release
104
+ - check_if_version_upgraded
105
+ steps :
106
+
107
+ with :
108
+ ref : ${{ github.ref }}
109
+
110
+ with :
111
+ node-version : ' 15'
112
+ registry-url : https://registry.npmjs.org/
113
+ - uses : bahmutov/npm-install@v1
114
+ - run : |
115
+ PACKAGE_MANAGER=npm
116
+ if [ -f "./yarn.lock" ]; then
117
+ PACKAGE_MANAGER=yarn
118
+ fi
119
+ $PACKAGE_MANAGER run build
120
+ -
run :
npx -y -p [email protected] enable_short_npm_import_path
121
+ env :
122
+ DRY_RUN : " 0"
123
+ - name : Publishing on NPM
124
+ run : |
125
+ if [ "$(npm show . version)" = "$VERSION" ]; then
126
+ echo "This version is already published"
127
+ exit 0
128
+ fi
129
+ if [ "$NODE_AUTH_TOKEN" = "" ]; then
130
+ echo "Can't publish on NPM, You must first create a secret called NPM_TOKEN that contains your NPM auth token. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets"
131
+ false
132
+ fi
133
+ EXTRA_ARGS=""
134
+ if [ "$IS_BETA" = "true" ]; then
135
+ EXTRA_ARGS="--tag beta"
136
+ fi
137
+ npm publish $EXTRA_ARGS
138
+ env :
139
+ NODE_AUTH_TOKEN : ${{secrets.NPM_TOKEN}}
140
+ VERSION : ${{ needs.check_if_version_upgraded.outputs.to_version }}
141
+ IS_BETA : ${{ needs.check_if_version_upgraded.outputs.is_release_beta }}
142
+
143
+ github_pages :
144
+ needs : test
145
+ runs-on : ubuntu-latest
146
+ if : github.event_name == 'push'
147
+ steps :
148
+ - uses : actions/checkout@v2
149
+
150
+ with :
151
+ node-version : ' 15'
152
+ - uses : bahmutov/npm-install@v1
153
+ - run : |
154
+ yarn build
155
+ yarn yarn_link
156
+ cd src/test/apps/spa
157
+ yarn build
158
+ - run : git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${{github.repository}}.git
159
+ env :
160
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
161
+ -
run :
npx -y -p [email protected] gh-pages -d src/test/apps/cra/build --dest test --add -u "github-actions-bot <[email protected] >"
0 commit comments