Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
feat: Release and pre-release pipelines with publish script (#224)
Browse files Browse the repository at this point in the history
Pipelines for release and pre-release on merges to master and dev respectively. Dev branch will release a beta to NPM and Master will release a patch to NPM

Resolves [AB#588]
  • Loading branch information
tbarlow12 authored Aug 16, 2019
1 parent 28d853d commit 7a8a948
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pipelines/publish-prerelease.yml
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions pipelines/publish-release.yml
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit 7a8a948

Please sign in to comment.