-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (45 loc) · 2.01 KB
/
cd.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
name: CD Pipeline
# After each successful PR merge to main branch.
on:
push:
branches:
- main
concurrency: cd
# Tbh, the most optimal way would be if I could reuse steps instead of jobs
# I guess that is possible if I would create separate folder for the action, but right now it seems like too heavy approach.
# Worth investigating later tho.
jobs:
cd_job:
uses: ./.github/workflows/build-and-test.yml
with:
fetch-depth: 0 # We must fetch whole history to be able to search for tags
# Don't use normal NPM publish actions in order to avoid token writing to .npmrc file.
post-run-function: |
tyras_post_run ()
{
PACKAGE_VERSION="$(cat "$1/package.json" | jq -rM .version)"
GIT_TAG_NAME="$1-v${PACKAGE_VERSION}"
if [[ -n "$(git ls-remote --tags origin "${GIT_TAG_NAME}")" ]]; then
echo "Detected that tag ${GIT_TAG_NAME} already is existing, not proceeding to publish package $1"
else
# The release can be performed, start by creating Git tag locally
# If there are any errors here, we won't end up in situation where NPM package is published, but no Git tag exists for it
git config --global user.email "[email protected]"
git config --global user.name "CD Automation"
git tag \
-a \
-m "Component $1 release ${PACKAGE_VERSION}" \
"${GIT_TAG_NAME}"
# Publish NPM package
cd "$1"
cp ../LICENSE ./LICENSE.txt
# Note - yarn doesn't have functionality to install package without saving it to package.json (!)
# So we use global install instead.
yarn global add "@jsdevtools/npm-publish@$(cat ../versions/npm-publish)"
npm-publish --access public --token "${NPM_PUBLISH_TOKEN}"
# Push Git tag
git push origin "${GIT_TAG_NAME}"
fi
}
secrets:
npm-publish-token: ${{ secrets.NPM_PUBLISH_TOKEN_PACKAGING }}