Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting workflows to a unified release delivery process #145

Merged
merged 11 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/actions/next-version-gen/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'Next version generator'
description: 'Generate next version number'
inputs:
publish-type:
description: 'Preview or Release'
required: true
preview-infix:
description: 'Infix used when creating a tag for the preview version'
default: '-insiders'
required: false
outputs:
next-version:
description: 'Next version number'
value: ${{ steps.version.outputs.next-version }}
next-version-tag:
description: 'Name of the tag used to mark version in git'
value: ${{ steps.version.outputs.next-version-tag }}
runs:
using: "composite"
steps:
- id: version
shell: pwsh
run: ${{github.action_path}}/generateVersion.ps1 -publishType "${{ inputs.publish-type }}" -previewInfix "${{ inputs.preview-infix }}"
66 changes: 66 additions & 0 deletions .github/actions/next-version-gen/generateVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
param(
$publishType,
$previewInfix
)

if($publishType -ne "Preview" -and $publishType -ne "Release") {
Write-Host "::error::Publish type can only be 'Preview' or 'Release'"
exit 1
}

$isPreview = $publishType -eq "Preview"

$pattern = "(?<Product>\w+)-v(?<Major>\d+)\.(?<Minor>\d+)\.(?<Patch>\w+)"

if ($env:GITHUB_REF_NAME -match $pattern) {
$product = $Matches['Product']
$majorVer = $Matches['Major']
$minorVer = $Matches['Minor']
$patchVer = $Matches['Patch']
}
else {
Write-Host "::error::Invalid branch name. Example valid name: vs-v0.2.x"
exit 1
}

if($patchVer -ne "x") {
Write-Host "::error::Path version number must be set to 'x'"
exit 1
}

if($minorVer % 2 -eq 1) {
Write-Host "::error::Minor version number must be even"
exit 1
}

if($isPreview) {
if($minorVer -eq 0) {
$newMinorVer = 999
$majorVer = $majorVer - 1
} else {
$newMinorVer = $minorVer - 1
}

$infix = $previewInfix
} else {
$newMinorVer = $minorVer
$infix = ""
}

$nextPathVer = 0

do {
$nextVersion = "$majorVer.$newMinorVer.$nextPathVer"
$nextVersionTag = "$product$infix-v$nextVersion"
git -C $env:GITHUB_WORKSPACE rev-parse "refs/tags/$nextVersionTag" --quiet 2> Out-Null
if($?) { $nextPathVer = $nextPathVer + 1 }
else { break }
} while($true)

"next-version=$nextVersion" >> $env:GITHUB_OUTPUT
"next-version-tag=$nextVersionTag" >> $env:GITHUB_OUTPUT

Write-Host "Next version: $nextVersion"
Write-Host "Next version tag name: $nextVersionTag"

exit 0
3 changes: 2 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
id: cody
with:
repository: sourcegraph/cody
prefix: vscode-
regex: 'vscode(-insiders)?-v\d+\.\d+\.\d+'
sort-tags: true

- name: Hash tag name
uses: pplanel/[email protected]
Expand Down
116 changes: 0 additions & 116 deletions .github/workflows/publish-release.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: Publish preview
name: Publish

on:
push:
tags:
- preview-v*.*.*
workflow_dispatch:
inputs:
publish:
type: choice
description: Publish type
default: Preview
options:
- Preview
- Release

# concurrency prevents multiple instances of the workflow from running at the same time,
# using `cancel-in-progress` to cancel any existing runs.
Expand All @@ -29,12 +35,12 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Extract version from tag
uses: nowsprinting/check-version-[email protected]

- name: Generate version
uses: ./.github/actions/next-version-gen
id: version
with:
prefix: preview-v
publish-type: ${{ github.event.inputs.publish }}

- name: Add msbuild
uses: microsoft/setup-msbuild@v2
Expand All @@ -61,13 +67,13 @@ jobs:
- name: Set version on AssemblyInfo.cs files
uses: dannevesdantas/[email protected]
with:
version: ${{ steps.version.outputs.full_without_prefix }}
version: ${{ steps.version.outputs.next-version }}
path: src/

- name: Set version for .vsixmanifest file
uses: cezarypiatek/[email protected]
with:
version: ${{ steps.version.outputs.full_without_prefix }}
version: ${{ steps.version.outputs.next-version }}
vsix-manifest-file: src\Cody.VisualStudio\source.extension.vsixmanifest

- name: Build extension (${{ env.Configuration }})
Expand Down Expand Up @@ -106,30 +112,51 @@ jobs:
files: TestResults/**/*.trx

#Publish
- name: Create git tag
uses: actions/github-script@v6
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ steps.version.outputs.next-version-tag }}",
sha: context.sha
})

- name: Create GitHub release
uses: ncipollo/[email protected]
with:
tag: ${{ steps.version.outputs.full }}
name: Cody for Visual Studio ${{ steps.version.outputs.full_without_prefix }}
tag: ${{ steps.version.outputs.next-version-tag }}
name: Cody for Visual Studio ${{ steps.version.outputs.next-version }}
prerelease: true
artifacts: src/Cody.VisualStudio/bin/${{ env.Configuration }}/Cody.VisualStudio.vsix

- name: Create custom VSIX feed
if: ${{ github.event.inputs.publish == 'Preview' }}
uses: ./.github/actions/create-vsix-feed
with:
vsix-directory: src/Cody.VisualStudio/bin/${{ env.Configuration }}
feed-file: feed/feed.xml
source-path: https://github.com/sourcegraph/cody-vs/releases/download/${{ steps.version.outputs.full }}/
source-path: https://github.com/sourcegraph/cody-vs/releases/download/${{ steps.version.outputs.next-version-tag }}/
gallery-name: "Sourcegraph preview gallery"

- name: Upload feed files as artifact
if: ${{ github.event.inputs.publish == 'Preview' }}
uses: actions/upload-pages-artifact@v3
with:
name: vsix-gallery-feed
path: feed/

- name: Deploy feed to GitHub Pages
if: ${{ github.event.inputs.publish == 'Preview' }}
uses: actions/deploy-pages@v4
with:
artifact_name: vsix-gallery-feed
artifact_name: vsix-gallery-feed

- name: Publish to Visual Studio Marketplace
if: ${{ github.event.inputs.publish == 'Release' }}
uses: cezarypiatek/[email protected]
with:
extension-file: src/Cody.VisualStudio/bin/${{ env.Configuration }}/Cody.VisualStudio.vsix
publish-manifest-file: src\Cody.VisualStudio\publishManifest.json
personal-access-code: ${{ secrets.CODY_VS_MARKETPLACE_RELEASE_TOKEN }}
3 changes: 1 addition & 2 deletions src/Cody.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\.github\workflows\build.yml = ..\.github\workflows\build.yml
..\.github\workflows\code-style.yml = ..\.github\workflows\code-style.yml
..\.github\workflows\nightly.yml = ..\.github\workflows\nightly.yml
..\.github\workflows\publish-preview.yml = ..\.github\workflows\publish-preview.yml
..\.github\workflows\publish-release.yml = ..\.github\workflows\publish-release.yml
..\.github\workflows\publish.yml = ..\.github\workflows\publish.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cody.Core.Tests", "Cody.Core.Tests\Cody.Core.Tests.csproj", "{9B46B477-E57A-4F19-A240-56D5D3C7EE8F}"
Expand Down