diff --git a/.github/actions/next-version-gen/action.yml b/.github/actions/next-version-gen/action.yml new file mode 100644 index 00000000..9d333616 --- /dev/null +++ b/.github/actions/next-version-gen/action.yml @@ -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 }}" \ No newline at end of file diff --git a/.github/actions/next-version-gen/generateVersion.ps1 b/.github/actions/next-version-gen/generateVersion.ps1 new file mode 100644 index 00000000..c94c281c --- /dev/null +++ b/.github/actions/next-version-gen/generateVersion.ps1 @@ -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 = "(?\w+)-v(?\d+)\.(?\d+)\.(?\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 \ No newline at end of file diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index e10ed5cc..de94cb93 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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/hash-calculator-action@v1.3.2 diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml deleted file mode 100644 index 61be43cf..00000000 --- a/.github/workflows/publish-release.yml +++ /dev/null @@ -1,116 +0,0 @@ -name: Publish release - -on: - push: - tags: - - release-v*.*.* - -# concurrency prevents multiple instances of the workflow from running at the same time, -# using `cancel-in-progress` to cancel any existing runs. -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: 16gb_16_core_large_window_runner - # do we want to run this on forks? - if: github.repository_owner == 'sourcegraph' - env: - NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages - Configuration: Release - - steps: - - uses: actions/checkout@v4 - - - name: Extract version from tag - uses: nowsprinting/check-version-format-action@v4.0.3 - id: version - with: - prefix: release-v - - - name: Add msbuild - uses: microsoft/setup-msbuild@v2 - - - name: Cache nuget - uses: actions/cache@v4 - with: - path: ${{ github.workspace }}/.nuget/packages - key: ${{ runner.os }}-nuget-${{ github.sha }} - restore-keys: ${{ runner.os }}-nuget- - - - name: Cache agent - id: cache-agent - uses: actions/cache@v4 - with: - path: src/Cody.VisualStudio/Agent - key: ${{ runner.os }}-agent-${{ hashFiles('agent/agent.version') }} - - - name: Build agent if needed - if: ${{ steps.cache-agent.outputs.cache-hit != 'true' }} - shell: pwsh - run: ./agent/runBuildAgent.ps1 - - - name: Set version on AssemblyInfo.cs files - uses: dannevesdantas/set-version-assemblyinfo@v.1.0.0 - with: - version: ${{ steps.version.outputs.full_without_prefix }} - path: src/ - - - name: Set version for .vsixmanifest file - uses: cezarypiatek/VsixVersionAction@1.2 - with: - version: ${{ steps.version.outputs.full_without_prefix }} - vsix-manifest-file: src\Cody.VisualStudio\source.extension.vsixmanifest - - - name: Build extension (${{ env.Configuration }}) - run: msbuild src/Cody.sln -t:Build -restore -verbosity:minimal -property:Configuration=${{ env.Configuration }} - - - name: Upload Cody.VisualStudio.vsix artifact - uses: actions/upload-artifact@v4 - with: - name: Cody.VisualStudio.vsix - path: src/Cody.VisualStudio/bin/${{ env.Configuration }}/Cody.VisualStudio.vsix - - #Running tests - - - name: Change Screen Resolution - shell: pwsh - run: Set-DisplayResolution -Width 1920 -Height 1080 -Force - - - name: Run tests - env: - Access_Token_UI_Tests: ${{ secrets.SRC_ACCESS_TOKEN_DOTCOM }} - WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS: '--remote-debugging-port=9222' - run: dotnet test src/*Tests/bin/${{ env.Configuration }}/*.Tests.dll --logger:trx --verbosity detailed - - - name: Upload screenshots for UI tests - uses: actions/upload-artifact@v4 - if: always() - with: - name: UI Tests Screenshots - path: src/Cody.VisualStudio.Tests/bin/${{ env.Configuration }}/Screenshots - retention-days: 20 - - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action/windows@v2 - if: always() - with: - files: TestResults/**/*.trx - - #Publish - - - name: Create GitHub release - uses: ncipollo/release-action@v1.14.0 - with: - tag: ${{ steps.version.outputs.full }} - name: Cody for Visual Studio ${{ steps.version.outputs.full_without_prefix }} - prerelease: false - artifacts: src/Cody.VisualStudio/bin/${{ env.Configuration }}/Cody.VisualStudio.vsix - - - name: Publish to Visual Studio Marketplace - uses: cezarypiatek/VsixPublisherAction@1.1 - 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 }} diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish.yml similarity index 72% rename from .github/workflows/publish-preview.yml rename to .github/workflows/publish.yml index 8436d29f..b8e8f9ea 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish.yml @@ -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. @@ -29,12 +35,12 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Extract version from tag - uses: nowsprinting/check-version-format-action@v4.0.3 + + - 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 @@ -61,13 +67,13 @@ jobs: - name: Set version on AssemblyInfo.cs files uses: dannevesdantas/set-version-assemblyinfo@v.1.0.0 with: - version: ${{ steps.version.outputs.full_without_prefix }} + version: ${{ steps.version.outputs.next-version }} path: src/ - name: Set version for .vsixmanifest file uses: cezarypiatek/VsixVersionAction@1.2 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 }}) @@ -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/release-action@v1.14.0 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 \ No newline at end of file + artifact_name: vsix-gallery-feed + + - name: Publish to Visual Studio Marketplace + if: ${{ github.event.inputs.publish == 'Release' }} + uses: cezarypiatek/VsixPublisherAction@1.1 + 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 }} \ No newline at end of file diff --git a/src/Cody.sln b/src/Cody.sln index 731601e0..3a1ee1e3 100644 --- a/src/Cody.sln +++ b/src/Cody.sln @@ -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}"