From c06853b2f418f29882c918799afc36b4c8c3c3a3 Mon Sep 17 00:00:00 2001 From: Tanner Barlow Date: Fri, 2 Aug 2019 12:04:08 -0700 Subject: [PATCH 1/4] feat: Release and pre-release pipelines with publish script --- pipelines/publish-prerelease.yml | 28 ++++++++++++++++++++++++++++ pipelines/publish-release.yml | 26 ++++++++++++++++++++++++++ scripts/publish.sh | 17 +++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 pipelines/publish-prerelease.yml create mode 100644 pipelines/publish-release.yml create mode 100644 scripts/publish.sh diff --git a/pipelines/publish-prerelease.yml b/pipelines/publish-prerelease.yml new file mode 100644 index 00000000..fe318f22 --- /dev/null +++ b/pipelines/publish-prerelease.yml @@ -0,0 +1,28 @@ +trigger: + # Semantic version tags with beta version at end + # Example: 1.2.3-4 + - refs/tags/[0-9]+\.[0-9]+\.[0-9]+-[0-9]+ +pr: none + +pool: + vmImage: 'ubuntu-latest' + +steps: +- task: NodeTool@0 + displayName: 'Use Node 10.x' + inputs: + versionSpec: 10.x + +- checkout: self + clean: true + persistCredentials: true + fetchDepth: 1 + +- task: Bash@3 + displayName: 'Publish serverless-azure-functions to NPM' + inputs: + targetType: filePath + filePath: ./scripts/publish.sh + arguments: 'prerelease' + env: + NPM_TOKEN: $(NPM_TOKEN) diff --git a/pipelines/publish-release.yml b/pipelines/publish-release.yml new file mode 100644 index 00000000..f16f2956 --- /dev/null +++ b/pipelines/publish-release.yml @@ -0,0 +1,26 @@ +trigger: + # Semantic version tags + # Example: 1.2.3 + - refs/tags/[0-9]+\.[0-9]+\.[0-9]+ + +pool: + vmImage: 'ubuntu-latest' + +steps: +- task: NodeTool@0 + displayName: 'Use Node 10.x' + inputs: + versionSpec: 10.x + +- checkout: self + clean: true + persistCredentials: true + fetchDepth: 1 + +- task: Bash@3 + displayName: 'Publish serverless-azure-functions to NPM' + inputs: + targetType: filePath + filePath: ./scripts/publish.sh + env: + NPM_TOKEN: $(NPM_TOKEN) diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100644 index 00000000..0d662727 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -eo pipefail + +# NOTE: build and publish are always executed in a package (e.g core) working directory +$(pwd)/scripts/build.sh + +## configure npm to sign commit +npm config set sign-git-tag true + +# NOTE: auth is taken care of via AzDO `npm auth` task. ENV vars would work as well. +if [ -z "$1" ]; then + echo "Publishing 'latest' to NPM..."; + npm publish +else + echo "Publishing 'prerelease' to NPM..."; + npm publish --tag=beta +fi From b56cf5312905cd6c231076fd1d64626f628ab14d Mon Sep 17 00:00:00 2001 From: Tanner Barlow Date: Fri, 2 Aug 2019 15:21:02 -0700 Subject: [PATCH 2/4] feat: Add version script and trigger on commits to dev or master --- pipelines/publish-prerelease.yml | 17 +++++++++++++--- pipelines/publish-release.yml | 17 +++++++++++++--- scripts/version.sh | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 scripts/version.sh diff --git a/pipelines/publish-prerelease.yml b/pipelines/publish-prerelease.yml index fe318f22..c33bf8d4 100644 --- a/pipelines/publish-prerelease.yml +++ b/pipelines/publish-prerelease.yml @@ -1,7 +1,7 @@ trigger: - # Semantic version tags with beta version at end - # Example: 1.2.3-4 - - refs/tags/[0-9]+\.[0-9]+\.[0-9]+-[0-9]+ + branches: + include: + - dev pr: none pool: @@ -18,6 +18,17 @@ steps: persistCredentials: true fetchDepth: 1 +- task: Bash@3 + name: BumpNpmVersion + displayName: Bump NPM Prerelease Version + inputs: + targetType: filePath + filePath: ./scripts/version.sh + arguments: 'serverless/serverless-azure-functions' + env: + NPM_TOKEN: $(NPM_TOKEN) + SOURCE_BRANCH: $(Build.SourceBranch) + - task: Bash@3 displayName: 'Publish serverless-azure-functions to NPM' inputs: diff --git a/pipelines/publish-release.yml b/pipelines/publish-release.yml index f16f2956..4bbcd667 100644 --- a/pipelines/publish-release.yml +++ b/pipelines/publish-release.yml @@ -1,7 +1,7 @@ trigger: - # Semantic version tags - # Example: 1.2.3 - - refs/tags/[0-9]+\.[0-9]+\.[0-9]+ + branches: + include: + - master pool: vmImage: 'ubuntu-latest' @@ -17,6 +17,17 @@ steps: persistCredentials: true fetchDepth: 1 +- task: Bash@3 + name: BumpNpmVersion + displayName: Bump NPM Prerelease Version + inputs: + targetType: filePath + filePath: ./scripts/version.sh + arguments: 'serverless/serverless-azure-functions' + env: + NPM_TOKEN: $(NPM_TOKEN) + SOURCE_BRANCH: $(Build.SourceBranch) + - task: Bash@3 displayName: 'Publish serverless-azure-functions to NPM' inputs: diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100644 index 00000000..a9481916 --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -euo pipefail + +PACKAGE_NAME=$1 +NPM_RELEASE_TYPE=${2-"prerelease"} + +# Get full branch name excluding refs/head from the env var SOURCE_BRANCH +SOURCE_BRANCH_NAME=${SOURCE_BRANCH/refs\/heads\/} + +# Configure git to commit as Azure Dev Ops +git config --local user.email "Serverless Azure Functions" +git config --local user.name "sls-az@microsoft.com" + +git pull origin ${SOURCE_BRANCH_NAME} +git checkout ${SOURCE_BRANCH_NAME} +echo Checked out branch: ${SOURCE_BRANCH_NAME} + +NPM_VERSION=`npm version ${NPM_RELEASE_TYPE}` +echo Set NPM version to: ${NPM_VERSION} + +# Stage update to package.json files +git add package.json +git add package-lock.json + +# Since there isn't a package.json at the root of repo +# and we have multiple packages within same repo +# we need to manually commit and tag in order to create unique tag names +git commit -m "Bumping NPM package ${PACKAGE_NAME} prerelease to version ${NPM_VERSION} ***NO_CI***" +SHA=`git rev-parse HEAD` + +git tag ${PACKAGE_NAME}-${NPM_VERSION} +git push origin ${SOURCE_BRANCH_NAME} --tags + +echo Pushed new tag: ${PACKAGE_NAME}-${NPM_VERSION} @ SHA: ${SHA:0:8} From da75799ad3804f1861733071e90db4896417d9bf Mon Sep 17 00:00:00 2001 From: "sls-az@microsoft.com" Date: Tue, 6 Aug 2019 09:29:08 -0700 Subject: [PATCH 3/4] feat: Update version script to work with GitHub --- scripts/version.sh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/scripts/version.sh b/scripts/version.sh index a9481916..6a7c37c0 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,13 +1,18 @@ #!/bin/bash set -euo pipefail +# Environment Variables Needed: +# SOURCE_BRANCH +# GITHUB_ACCESS_TOKEN + PACKAGE_NAME=$1 NPM_RELEASE_TYPE=${2-"prerelease"} # Get full branch name excluding refs/head from the env var SOURCE_BRANCH SOURCE_BRANCH_NAME=${SOURCE_BRANCH/refs\/heads\/} -# Configure git to commit as Azure Dev Ops +# Configure git to commit as SLS Azure Functions Service Account +echo "Configuring git to use service account..." git config --local user.email "Serverless Azure Functions" git config --local user.name "sls-az@microsoft.com" @@ -15,20 +20,12 @@ git pull origin ${SOURCE_BRANCH_NAME} git checkout ${SOURCE_BRANCH_NAME} echo Checked out branch: ${SOURCE_BRANCH_NAME} -NPM_VERSION=`npm version ${NPM_RELEASE_TYPE}` +NPM_VERSION=`npm version ${NPM_RELEASE_TYPE} -m "Update version ${NPM_RELEASE_TYPE} ***NO_CI***"` echo Set NPM version to: ${NPM_VERSION} -# Stage update to package.json files -git add package.json -git add package-lock.json - -# Since there isn't a package.json at the root of repo -# and we have multiple packages within same repo -# we need to manually commit and tag in order to create unique tag names -git commit -m "Bumping NPM package ${PACKAGE_NAME} prerelease to version ${NPM_VERSION} ***NO_CI***" SHA=`git rev-parse HEAD` -git tag ${PACKAGE_NAME}-${NPM_VERSION} -git push origin ${SOURCE_BRANCH_NAME} --tags +git remote add authOrigin https://${GITHUB_ACCESS_TOKEN}@github.com/serverless/serverless-azure-functions.git +git push authOrigin ${SOURCE_BRANCH_NAME} --tags echo Pushed new tag: ${PACKAGE_NAME}-${NPM_VERSION} @ SHA: ${SHA:0:8} From adf67f669e1b4ee61cf644664c2a8eebc20a5dfa Mon Sep 17 00:00:00 2001 From: Tanner Barlow Date: Thu, 15 Aug 2019 14:56:46 -0700 Subject: [PATCH 4/4] fix: Respond to PR feedback --- pipelines/publish-prerelease.yml | 4 ++++ pipelines/publish-release.yml | 19 ++++--------------- scripts/publish.sh | 6 +----- scripts/version.sh | 8 ++++---- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/pipelines/publish-prerelease.yml b/pipelines/publish-prerelease.yml index c33bf8d4..3634d30d 100644 --- a/pipelines/publish-prerelease.yml +++ b/pipelines/publish-prerelease.yml @@ -4,6 +4,9 @@ trigger: - dev pr: none +variables: +- group: npm-release-credentials + pool: vmImage: 'ubuntu-latest' @@ -27,6 +30,7 @@ steps: arguments: 'serverless/serverless-azure-functions' env: NPM_TOKEN: $(NPM_TOKEN) + GITHUB_ACCESS_TOKEN: $(GITHUB_ACCESS_TOKEN) SOURCE_BRANCH: $(Build.SourceBranch) - task: Bash@3 diff --git a/pipelines/publish-release.yml b/pipelines/publish-release.yml index 4bbcd667..b7618233 100644 --- a/pipelines/publish-release.yml +++ b/pipelines/publish-release.yml @@ -1,11 +1,11 @@ -trigger: - branches: - include: - - master +trigger: none pool: vmImage: 'ubuntu-latest' +variables: +- group: npm-release-credentials + steps: - task: NodeTool@0 displayName: 'Use Node 10.x' @@ -17,17 +17,6 @@ steps: persistCredentials: true fetchDepth: 1 -- task: Bash@3 - name: BumpNpmVersion - displayName: Bump NPM Prerelease Version - inputs: - targetType: filePath - filePath: ./scripts/version.sh - arguments: 'serverless/serverless-azure-functions' - env: - NPM_TOKEN: $(NPM_TOKEN) - SOURCE_BRANCH: $(Build.SourceBranch) - - task: Bash@3 displayName: 'Publish serverless-azure-functions to NPM' inputs: diff --git a/scripts/publish.sh b/scripts/publish.sh index 0d662727..7a4a8077 100644 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,13 +1,9 @@ #!/bin/bash set -eo pipefail -# NOTE: build and publish are always executed in a package (e.g core) working directory $(pwd)/scripts/build.sh -## configure npm to sign commit -npm config set sign-git-tag true - -# NOTE: auth is taken care of via AzDO `npm auth` task. ENV vars would work as well. +# NOTE: auth is taken care of via NPM_TOKEN env variable if [ -z "$1" ]; then echo "Publishing 'latest' to NPM..."; npm publish diff --git a/scripts/version.sh b/scripts/version.sh index 6a7c37c0..d6b54ebe 100644 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -18,14 +18,14 @@ git config --local user.name "sls-az@microsoft.com" git pull origin ${SOURCE_BRANCH_NAME} git checkout ${SOURCE_BRANCH_NAME} -echo Checked out branch: ${SOURCE_BRANCH_NAME} +echo "Checked out branch: ${SOURCE_BRANCH_NAME}" -NPM_VERSION=`npm version ${NPM_RELEASE_TYPE} -m "Update version ${NPM_RELEASE_TYPE} ***NO_CI***"` -echo Set NPM version to: ${NPM_VERSION} +NPM_VERSION=`npm version ${NPM_RELEASE_TYPE} -m "release: Update ${NPM_RELEASE_TYPE} version to %s ***NO_CI***"` +echo "Set NPM version to: ${NPM_VERSION}" SHA=`git rev-parse HEAD` git remote add authOrigin https://${GITHUB_ACCESS_TOKEN}@github.com/serverless/serverless-azure-functions.git git push authOrigin ${SOURCE_BRANCH_NAME} --tags -echo Pushed new tag: ${PACKAGE_NAME}-${NPM_VERSION} @ SHA: ${SHA:0:8} +echo "Pushed new tag: ${PACKAGE_NAME}-${NPM_VERSION} @ SHA: ${SHA:0:8}"