Last active
September 30, 2020 14:39
-
-
Save mpetuska/cbd1474920bbc984c085c6b9d551e2f1 to your computer and use it in GitHub Desktop.
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
parameters: | |
- name: packageManager | |
default: yarn | |
values: | |
- yarn | |
- npm | |
- name: jfrogUser | |
- name: jfrogToken | |
- name: bundleDir | |
default: build/ | |
- name: nodeBundle | |
default: '' | |
- name: workingDirectory | |
default: . | |
type: string | |
- name: pushVersionCommit | |
type: boolean | |
default: true | |
- name: isMonorepo | |
type: boolean | |
default: false | |
steps: | |
- checkout: self | |
persistCredentials: true | |
- bash: | | |
git config --global user.email "BitBucket@mycompany.org.uk" | |
git config --global user.name "Azure DevOps" | |
displayName: Setup Git credentials | |
- bash: | | |
curl -u${{parameters.jfrogUser}}:${{parameters.jfrogToken}} https://mycompany.jfrog.io/artifactory/api/npm/auth > ~/.npmrc; | |
echo 'registry=https://mycompany.jfrog.io/artifactory/api/npm/npm-dev-local' >> ~/.npmrc; | |
displayName: Login to JFrog | |
workingDirectory: ${{parameters.workingDirectory}} | |
- ${{ if ne(parameters.nodeBundle, '') }}: | |
- task: DownloadPipelineArtifact@2 | |
inputs: | |
artifact: ${{parameters.nodeBundle}} | |
path: $(Build.SourcesDirectory)/${{parameters.workingDirectory}}/${{parameters.bundleDir}} | |
- bash: | | |
if [[ "$(echo '$(Build.SourceVersionMessage)' | sed ':a;N;$!ba;s/\n/ /g')" =~ (v[0-9]+\.[0-9]+\.[0-9]+) && $(Build.Reason) != 'Manual' ]] | |
then | |
echo 'Explicit version detected, not bumping anymore'; | |
else | |
echo "##vso[task.setvariable variable=PUBLISH_TO_JFROG]true"; | |
CMD_PREFIX=""; | |
TAG_PREFIX='v'; | |
isMonorepo=${{parameters.isMonorepo}} | |
if [[ "${isMonorepo^^}" == "TRUE" ]]; then | |
TAG_PREFIX='$(Build.DefinitionName) v'; | |
TAG_PREFIX="${TAG_PREFIX// /_}"; | |
fi | |
if [[ "${{parameters.packageManager}}" == "yarn" ]]; then | |
CMD_PREFIX="--"; | |
yarn config set version-tag-prefix $TAG_PREFIX; | |
else | |
npm config set tag-version-prefix $TAG_PREFIX; | |
fi | |
BUILD_URL="$(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)" | |
GIT_MESSAGE="[ci skip][EEV-818] v%s | |
Produced by build: $BUILD_URL"; | |
if [[ "$BUILD_SOURCEBRANCHNAME" == "master" ]]; then | |
git pull origin master; | |
mkdir .git -p | |
echo 'No explicit version detected, bumping patch' | |
${{parameters.packageManager}} version ${CMD_PREFIX}patch --message "$GIT_MESSAGE" --force; | |
pushVersionCommit=${{parameters.pushVersionCommit}} | |
if [[ "${pushVersionCommit^^}" == "TRUE" ]]; then | |
echo "Pushing git version commit"; | |
git push --follow-tags --no-verify origin HEAD:$BUILD_SOURCEBRANCH; | |
fi | |
else | |
echo 'No explicit version detected, bumping preid' | |
${{parameters.packageManager}} version --no-git-tag-version ${CMD_PREFIX}prerelease --preid $(Build.BuildNumber) --message "$GIT_MESSAGE"; | |
fi | |
fi | |
displayName: Bump Build Version | |
workingDirectory: ${{parameters.workingDirectory}} | |
- bash: ${{parameters.packageManager}} publish --verbose; | |
condition: eq(variables['PUBLISH_TO_JFROG'], 'true') | |
displayName: Publish to JFrog | |
workingDirectory: ${{parameters.workingDirectory}} | |
env: | |
CI: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment