Skip to content

Commit

Permalink
automated set-version for AzDevOps official builds with release-it (m…
Browse files Browse the repository at this point in the history
…icrosoft#87)

Co-authored-by: david@DAVID-PC <[email protected]>
  • Loading branch information
davidjenni and david@DAVID-PC authored May 7, 2022
1 parent 5a86bf6 commit a8590b5
Show file tree
Hide file tree
Showing 7 changed files with 4,849 additions and 121 deletions.
34 changes: 17 additions & 17 deletions .azure-pipelines/OfficialBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ variables:
# set the following in the pipeline's web UI editor:
# GITHUB_TOKEN # GitHub PAT with scopes: repo; must have SSO enabled for GH org 'microsoft' for corp user
# AZ_DevOps_Read_PAT # PAT to read from AzDO feed in msazure
# VSIX_PATCH_VERSION # VSIX package's patch version; must be manually managed for now!
# isEsrpEnabled : # true/false

trigger: none
Expand All @@ -29,44 +28,45 @@ pool:
vmImage: 'windows-latest'

steps:
- script: echo "##vso[build.updatebuildnumber]0.1.$(VSIX_PATCH_VERSION)
displayName: Set AzDO Job/Build version

# - script: mkdir package && echo $(VSIX_VERSION),$(Build.SourceVersion) > package/version.csv
# displayName: Capture build version in package/version.csv

- task: NodeTool@0
displayName: 'Use nodejs 16.x'
inputs:
versionSpec: '16.x'

- script: |
node --version
npm --version
git --version
displayName: Toolchain info

# need to authenticate to npm package feed in microsoft/powerplatform-cli-wrapper (see also README.md)
- task: npmAuthenticate@0
displayName: 'setup package feed authN with github'
inputs:
workingFile: .npmrc
customEndpoint: github.com_npm_davidjenni

- task: Npm@1
displayName: 'Restore (npm install)'
inputs:
command: custom
customCommand: ci

# authN for pushing tags via release-it
- task: Npm@1
displayName: 'set git repo authN'
inputs:
command: custom
customCommand: run set-git-authn -- "$(GITHUB_TOKEN)"

- task: Npm@1
displayName: 'Restore (npm install)'
displayName: 'set-version to calculate patch-version with release-it'
inputs:
command: custom
customCommand: ci

# - task: Npm@1
# displayName: 'auto-increment version'
# inputs:
# command: custom
# customCommand: run increment-version
customCommand: run set-version

- task: Npm@1
displayName: 'Build'
displayName: 'Build and prepare-pack'
inputs:
command: custom
customCommand: run prepare-pack -- --feedPAT $(AZ_DevOps_Read_PAT)
Expand All @@ -75,7 +75,7 @@ steps:
displayName: 'Package VSIX'
inputs:
command: custom
customCommand: run pack -- --patch $(VSIX_PATCH_VERSION) --isOfficial
customCommand: run pack -- --isOfficial

# https://microsoft.sharepoint.com/teams/prss/esrp/info/ESRP%20Onboarding%20Wiki/Generating%20Signing%20JSON.aspx
# https://microsoft.sharepoint.com/teams/prss/esrp/info/ESRP%20Onboarding%20Wiki/Selecting%20CodeSign%20Certificates.aspx
Expand Down
33 changes: 33 additions & 0 deletions .release-it.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# https://github.com/release-it/release-it/blob/master/config/release-it.json

hooks: {}

# https://github.com/release-it/release-it/blob/master/docs/git.md
git:
addUntrackedFiles: false
commit: false
push: true
# need to specify pushRepo, since AzDO insists on disconnected refs, breaking upstream
requireUpstream: false
pushArgs: [ '--tags' ]
pushRepo: https://github.com/microsoft/powerplatform-build-tools

# requireBranch: main
requireCommits: false
requireCleanWorkingDir: false
tag: true
tagArgs: [ '--force' ]
tagAnnotation: |
build ${version}:
${changelog}
tagName: 'v${version}'

#https://github.com/release-it/release-it/blob/master/docs/npm.md
npm:
ignoreVersion: true
publish: false

# https://github.com/release-it/release-it/blob/master/docs/github-releases.md
github:
draft: true
release: false
2 changes: 1 addition & 1 deletion extension/extension-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "PowerPlatform-BuildTools",
"publisher": "microsoft-IsvExpTools",
"version": "1.0.29",
"version": "1.0.0",
"name": "Power Platform Build Tools",
"description": "Automate common build and deployment tasks related to Power Platform",
"categories": ["Azure Pipelines"],
Expand Down
8 changes: 8 additions & 0 deletions gulp/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const path = require("path");
const webpack = require("webpack");

module.exports = function compile() {
// detect if running on an AzDevOps build agent
const packageJson = require("../package.json");
if (process.env.BUILD_BUILDID) {
// https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash
console.log(`##vso[build.updatebuildnumber]${packageJson.version}`);
} else {
console.log(`local build: ${packageJson.version}`);
}
return new Promise((resolve) => {
const config = require("../webpack.config");
webpack(config).run(onBuild(resolve));
Expand Down
12 changes: 8 additions & 4 deletions gulp/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const packagesDir = `${outDir}/packages`;
const isOfficial = argv.isOfficial || false;

module.exports = async () => {
const packageJson = require("../package.json");
const manifest = require("../extension/extension-manifest.json");

await createDir(outDir);
Expand All @@ -22,7 +23,7 @@ module.exports = async () => {
await generateNpmPackage();
await copyDependencies();
await removeInvalidFiles();
const taskVersion = setVersion(manifest);
const taskVersion = setVersion(packageJson, manifest);
setContributions(manifest);
await addTaskFiles();
await copy("extension/assets", `${stagingDir}/assets`, {
Expand Down Expand Up @@ -82,15 +83,18 @@ async function findFiles(search, root) {
});
}

function setVersion(manifest) {
const currentVersionParts = manifest.version.split(".");
function setVersion(packageJson, manifest) {
const currentVersionParts = packageJson.version.split(".");
const [currentMajor, currentMinor, currentPatch] = currentVersionParts;

const major = argv.major || currentMajor;
const minor = argv.minor || currentMinor;
const patch = argv.patch || currentPatch;

manifest.version = `${major}.${minor}.${patch}`;
const version = `${major}.${minor}.${patch}`;
packageJson.version = version;
manifest.version = version;

return {
major: 0, // all tasks are currently v0, see task paths
minor: minor,
Expand Down
Loading

0 comments on commit a8590b5

Please sign in to comment.