diff --git a/pipelines/publish-prerelease.yml b/pipelines/publish-prerelease.yml new file mode 100644 index 00000000..3634d30d --- /dev/null +++ b/pipelines/publish-prerelease.yml @@ -0,0 +1,43 @@ +trigger: + branches: + include: + - dev +pr: none + +variables: +- group: npm-release-credentials + +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 + name: BumpNpmVersion + displayName: Bump NPM Prerelease Version + inputs: + targetType: filePath + filePath: ./scripts/version.sh + arguments: 'serverless/serverless-azure-functions' + env: + NPM_TOKEN: $(NPM_TOKEN) + GITHUB_ACCESS_TOKEN: $(GITHUB_ACCESS_TOKEN) + SOURCE_BRANCH: $(Build.SourceBranch) + +- 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..b7618233 --- /dev/null +++ b/pipelines/publish-release.yml @@ -0,0 +1,26 @@ +trigger: none + +pool: + vmImage: 'ubuntu-latest' + +variables: +- group: npm-release-credentials + +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..7a4a8077 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -eo pipefail + +$(pwd)/scripts/build.sh + +# NOTE: auth is taken care of via NPM_TOKEN env variable +if [ -z "$1" ]; then + echo "Publishing 'latest' to NPM..."; + npm publish +else + echo "Publishing 'prerelease' to NPM..."; + npm publish --tag=beta +fi diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100644 index 00000000..d6b54ebe --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,31 @@ +#!/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 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" + +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} -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}"