Merge pull request #15 from ty-ras/issue/14-expose-koa-options #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |