-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (48 loc) · 2.21 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
51
52
53
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 ()
{
TYRAS_LIB_DIR="$1"
TYRAS_LIB_NAME="$(basename "${TYRAS_LIB_DIR}")"
PACKAGE_VERSION="$(cat "${TYRAS_LIB_DIR}/package.json" | jq -rM .version)"
GIT_TAG_NAME="${TYRAS_LIB_NAME}-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 ${TYRAS_LIB_NAME} release ${PACKAGE_VERSION}" \
"${GIT_TAG_NAME}"
# Publish NPM package
TYRAS_GIT_ROOT="$(pwd)"
cd "${TYRAS_LIB_DIR}"
cp "${TYRAS_GIT_ROOT}/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 "${TYRAS_GIT_ROOT}/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 }}