Skip to content

Merge pull request #96 from ty-ras/dependabot/npm_and_yarn/code/extra… #126

Merge pull request #96 from ty-ras/dependabot/npm_and_yarn/code/extra…

Merge pull request #96 from ty-ras/dependabot/npm_and_yarn/code/extra… #126

Workflow file for this run

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 ${TYRAS_LIB_NAME}"
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 "cd-automation@ty-ras.project"
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_PACKAGING }}