Giter Site home page Giter Site logo

semantic-release-ado's Introduction

semantic-release-ado

semantic-release Build Status

Semantic release plugin for automatic builds on Azure DevOps pipelines.

Step Description
analyzeCommits If configured to do so, stores the current version as an Azure DevOps pipeline variable.
verifyRelease Stores the next version as an Azure DevOps pipeline variable availabe to downstream steps on the job.

Install

$ npm install -D semantic-release-ado

Usage

The plugin can be configured in the semantic-release configuration file:

YAML:

plugins:
  - @semantic-release-ado"

JSON:

{
  "plugins": [
    "semantic-release-ado",
  ]
}

The generated version number will be stored on a variable availabe to downstream steps on the job. By default this variable is named nextRelease, but the name can be configured in the plugin options. The behavior when no new release is available can be configured with setOnlyOnRelease.

Configuration

Options

Options Desctiption
varName Name of the variable that will store the next version. Defaults to nextRelease.
setOnlyOnRelease Bool. Determines if the variable with the new version will be set only when a new version is available.
If set to false, the next version variable will store the last released version when no new version is available.
Defaults to true.
isOutput Bool. Determines whether the version will be set as an output variable, so it is available in later stages.
Defaults to false.

The following examples store the generated version number in a variable named version.

YAML:

plugins:
  - - "semantic-release-ado"
    - varName: "version"
      setOnlyOnRelease: true
      isOutput: true #defaults to false

JSON:

{
  "plugins": [
    ["semantic-release-ado", {
      "varName": "version",
      "setOnlyOnRelease": true,
      "isOutput": true //defaults to false
    }],
  ]
}

Azure DevOps build pipeline YAML example:

Using the variable on the seme job:

jobs:
- job: Build
  pool:
    vmImage: 'vs2017-win2016'
  steps:

  - script: >
      npx -p semantic-release
      -p @semantic-release/git
      -p semantic-release-ado
      semantic-release
    env: { GH_TOKEN: $(GitHubToken) }
    displayName: 'Semantic release'

  - script: echo $(nextRelease)
    displayName: 'Show next version'

Using the variable on a later job:

Configuration:

Below is the configuration for setting isOutput to true, which will allow the variable to be referenced from other jobs/stages

JSON:

{
  "plugins": [
    ["semantic-release-ado", {
      "varName": "version",
      "setOnlyOnRelease": true,
      "isOutput": true //sets version as output for later use
    }],
  ]
}

In another job:

jobs:
- job: Job1
  pool:
    vmImage: 'vs2017-win2016'

  steps:
  - script: >
      npx -p semantic-release
      -p @semantic-release/git
      -p semantic-release-ado
      semantic-release
    env: { GH_TOKEN: $(GitHubToken) }
    displayName: 'Semantic release'

- job: Job2
  dependsOn: Job1
  pool:
    vmImage: 'vs2017-win2016'
  variables:
    versionNumber: $[ dependencies.Job1.outputs['setOutputVar.versionNumber'] ]

  steps:
  - script: echo $(versionNumber)
    displayName: 'Show next version'

In another stage:

stages: 
  - stage: Stage1
    jobs:
    - job: Job1
      pool:
        vmImage: 'vs2017-win2016'

      steps:
      - script: >
          npx -p semantic-release
          -p @semantic-release/git
          -p semantic-release-ado
          semantic-release
        env: { GH_TOKEN: $(GitHubToken) }
        name: semantic-release
        displayName: 'Semantic release'

  - stage: Stage2
    dependsOn: Stage1
    #want to make sure variable is set before we continue to run the stage
    condition: and(succeeded(), ne(dependencies.Stage1.outputs['Job1.semantic-release.version'], ''))
    jobs:
    - job: Job2
      variables:
          versionNumber: $[ stageDependencies.Stage1.Job1.outputs['semantic-release.version'] ]
      pool:
        vmImage: 'vs2017-win2016'
      variables:
        versionNumber:
      steps:
      - script: echo $(versionNumber)
        displayName: 'Show next version'

semantic-release-ado's People

Contributors

dependabot[bot] avatar hmg-frontend avatar jotatoledo avatar lluchmk avatar ritzlgrmft avatar semantic-release-bot avatar viktorlarsson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

semantic-release-ado's Issues

Variable $(nextRelease) is not set in the same ado script context

  - script: |
      npx \
      -p semantic-release-yaml \
      -p semantic-release-ado \
      -p @semantic-release/changelog \
      semantic-release
      contents="$(jq '.version = "$(nextRelease)"' package.json)" && \
      echo -E "${contents}" > package.json

The above example doesn't work. I have to put the last two lines in a separate pipeline script in order to get a value inside the variable nextRelease.

Quick question

Hi guys

Does sematic-release-ado generate CHANGELOG as well? if yes, is it using conventional-changelog-config-spec ?

Best
Hmendezm

Can't seem to make it work.. nextRelease is always empty

Hello, I'm having some trouble and I hope you can help me resolve it.

If we're following the configuration example for jobs and outputting of nextRelease it always comes out either empty or won't even pass the pipeline if we straight up use the code sample.

Perhaps I am missing something?

My powershell output variable task fails on $(nextRelease) and all echos don't show anything

Code used:

- job: Tag_Release
  displayName: Tag release
  pool:
    vmImage: 'vs2017-win2016'
  steps:

  - script:  >
      npx 
      -p semantic-release
      -p @semantic-release/git
      -p semantic-release-ado
      semantic-release
    displayName: 'Tag release (semantic)'
    env: { GH_TOKEN: $(GitHubToken) }

  - script: echo $(nextRelease) <- tried various combination of outputting and no result
  
    # Output version number to be available to other jobs
  - powershell: |
      echo "##vso[task.setvariable variable=versionNumber;isOutput=true]$(nextRelease)" <-- This fails. Tried $env:nextRelease
    name: versionOutput
    displayName: Release version output

My pipeline output is

[7:11:10 AM] [semantic-release] › ℹ  Running semantic-release version 17.2.2
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/npm"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/github"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/npm"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/npm"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/github"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/npm"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/github"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "success" from "@semantic-release/github"
[7:11:11 AM] [semantic-release] › ✔  Loaded plugin "fail" from "@semantic-release/github"
[7:11:15 AM] [semantic-release] › ✔  Run automated release from branch main on repository https://[secure]@github.com/maranmaran/Pricely-protobuf-monorepo
[7:11:16 AM] [semantic-release] › ✔  Allowed to push to the Git repository
[7:11:16 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/npm"
[7:11:16 AM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/npm"
[7:11:16 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/github"
[7:11:16 AM] [semantic-release] [@semantic-release/github] › ℹ  Verify GitHub authentication
[7:11:17 AM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/github"
[7:11:17 AM] [semantic-release] › ℹ  Found git tag v1.3.1 associated with version 1.3.1 on branch main
[7:11:17 AM] [semantic-release] › ℹ  Found 2 commits since last release
[7:11:17 AM] [semantic-release] › ℹ  Start step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[7:11:17 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: no message
[7:11:17 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The commit should not trigger a release
[7:11:17 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analyzing commit: feat: install
[7:11:17 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  The release type for the commit is minor
[7:11:17 AM] [semantic-release] [@semantic-release/commit-analyzer] › ℹ  Analysis of 2 commits complete: minor release
[7:11:17 AM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"

I don't see semantic-release-ado being loaded as plugin :/

Fixed it with proper package.json config

  "release": {
    "branches": [ "main" ],
    "plugins": [
      "@semantic-release/commit-analyzer",
      "@semantic-release/release-notes-generator",
      "@semantic-release/npm",
      "@semantic-release/changelog",
      "@semantic-release/git",
      "semantic-release-ado"
    ]
  }
  npx 
      -p semantic-release
      -p @semantic-release/changelog
      -p @semantic-release/git
      -p semantic-release-ado
      semantic-release

Azure DevOps authentication failing

How exactly should I authenticate to my Azure DevOps repo?

Currently running into the following error:

[4:22:40 PM] [semantic-release] › ℹ  Running semantic-release version 17.1.1
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/changelog"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/github"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/git"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "semantic-release-ado"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/changelog"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/git"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "semantic-release-ado"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/github"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/github"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "success" from "@semantic-release/github"
[4:22:40 PM] [semantic-release] › ✔  Loaded plugin "fail" from "@semantic-release/github"
[4:22:40 PM] [semantic-release] › ✖  An error occurred while running semantic-release: Error: Command failed with exit code 128: git ls-remote --heads https://[secure]@dev.azure.com/<orgName>/Versioning/_git/Versioning
fatal: Authentication failed for 'https://dev.azure.com/<orgName>/Versioning/_git/Versioning/'

My pipeline:

trigger: none

jobs:
- job: Build
  pool:
    vmImage: 'ubuntu-latest'
  steps:

  - script: >
        npx -p semantic-release
        -p @semantic-release/changelog
        -p @semantic-release/git
        -p semantic-release-ado
        semantic-release
    env: { GH_TOKEN: $(GitHubToken) }
    displayName: 'Semantic release'

  - script: echo $(nextRelease)
    displayName: 'Show next version'

I'm guessing the GH_TOKEN environment variable is wrong, as I'm trying to authenticate to AzDo, not GitHub?

Issues with semantic-release peer dependancy on 1.3.0

Having some issues when installing this plugin

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @dignisia/[email protected]
npm ERR! Found: @semantic-release/[email protected]
npm ERR! node_modules/@semantic-release/changelog
npm ERR!   @semantic-release/changelog@"6.0.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! @semantic-release/changelog@"6.0.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/semantic-release
npm ERR!   peer semantic-release@">=18.0.0" from @semantic-release/[email protected]
npm ERR!   node_modules/@semantic-release/changelog
npm ERR!     @semantic-release/changelog@"6.0.1" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/viktorsarstrom/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:

Should probably bump it to 18.0.x (9?)?

"semantic-release": ">=11.0.0 <18.0.0"

The build number format $(nextRelease)" contains invalid character

Hello, can't get remantic-release-ado working with the latest semantic-release library.
It fails with an error ##[error]TF209010
LOG:

[8:42:42 PM] [semantic-release] › ✔  Published release 1.2.2 on default channel
Async Command Start: Update Build Number
Async Command End: Update Build Number
##[error]TF209010: The build number format $(nextRelease)" contains invalid character(s), is too long, or ends with '.'. The maximum length of a build number is 255 characters. Characters which are not allowed include '"', '/', ':', '<', '>', '\', '|', '?', '@', and '*'.
Finishing: Release

Here is my pipeline:

  - bash: |
      npm install -g semantic-release @semantic-release/exec semantic-release-plus @semantic-release-plus/docker semantic-release-ado
      semantic-release
    displayName: 'Release'
    env:
      GITHUB_TOKEN: $(GH_TOKEN)
      DOCKER_REPOSITORY_NAME: $(DOCKER_REPOSITORY_NAME)
      DOCKER_REPOSITORY: $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(DOCKER_REPOSITORY_NAME)

Please, help!

Allow configuring behavior on nextRelease when there's no relevant changes.

Versions 1.0.x didn't set the nextRelease variable when there's no relevant changes. 1.1.0 changed this behavior, setting the value to the previous versions.
A configuration option should be added to allow configuring this behavior.

Original comment:
I understand this feature but I was using the empty state of the nextRelease variable if there is no relevant change. Do you think it is possible to add an option to enable/disable this new feature. It would be great! Thank you all!

Originally posted by @panquez in #2 (comment)

Determine if semantic-release is releasable while setOnlyOnRelease is false

In our configuration, we have setOnlyOnRelease to false. We are trying to figure out how we'd go about tagging our build artifact to indicate that it is a releasable build. This is trivial with setOnlyOnRelease set to true as we'd simply check for the existence of nextRelease variable.

However, we set setOnlyOnRelease to false so that we can get the current version number regardless of if there is a new release.

Considering this, would it make sense to add a mechanism to indicate if there was a release beyond the calculated version number being present in the variable?

Changing the value of the nextRelease variable would introduce a breaking change. To avoid that, perhaps a second variable could be set instead, if a breaking change is not desired. Variable name proposal would be releasable, and potentially configurable as well.

For example:

analyzeCommits.js

module.exports = async (pluginConfig, { lastRelease: { version }, logger }) => {
  const setOnlyOnRelease = pluginConfig.setOnlyOnRelease === undefined ? true : !!pluginConfig.setOnlyOnRelease

  if (!setOnlyOnRelease) {
    const varName = pluginConfig.varName || 'nextRelease'
    const isOutput = pluginConfig.isOutput|| false
    logger.log(`Setting current version ${version} to the env var ${varName}`)

    console.log(`##vso[task.setvariable variable=${varName};isOutput=${isOutput}]${version}`)
    console.log(`##vso[task.setvariable variable=releasable;isOutput=${isOutput}]false`);
  }
}

verifyRelease.js

module.exports = async (pluginConfig, { nextRelease: { version }, logger }) => {
  const varName = pluginConfig.varName || 'nextRelease'
  const isOutput = pluginConfig.isOutput || false

  logger.log(`Setting version ${version} to the env var ${varName}`)

  console.log(`##vso[task.setvariable variable=${varName};isOutput=${isOutput}]${version}`)
  console.log(`##vso[task.setvariable variable=releasable;isOutput=${isOutput}]true`);
}

I suppose it might be possible to add the plugin twice to the semantic-release configuration, each with a different semantic-release-ado configuration. One would have setOnlyOnRelease false with the default variable name, and the other with setOnlyOnRelease true and the variable name configured as my proposed releasable.

I'm not sure if that is allowed or not by the semantic-release config. I will give it a try and report back.

Perhaps there is a completely different way I should be going about figuring out if my build is releasable or not. Our release cycle releases to NPM in this case, so we can't re-publish previous versions.

Thanks for the work on this plugin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.