Bump styfle/cancel-workflow-action from 0.10.0 to 0.12.1 #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
env: | |
Config: Release | |
Debug: ${{ false }} | |
SkipReleaseNotes: ${{ true }} | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
jobs: | |
Build: | |
runs-on: windows-latest | |
env: | |
TFSCMDLETS_ACCESS_TOKEN: ${{ secrets.TFSCMDLETS_TOKEN }} | |
TFSCMDLETS_COLLECTION_URL: 'https://dev.azure.com/tfscmdlets' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Initialize CodeQL | |
uses: github/codeql-action/init@v2 | |
with: | |
languages: csharp | |
- name: Build module | |
id: build_module | |
shell: pwsh | |
run: | | |
./Build.ps1 -Targets Package -Config ${{ env.Config }} -Verbose:$${{ env.Debug }} -SkipReleaseNotes:$${{ env.SkipReleaseNotes }} | |
- name: Perform CodeQL Analysis | |
uses: github/codeql-action/analyze@v2 | |
- name: Publish Nuget | |
uses: actions/upload-artifact@v3 | |
with: | |
name: nuget | |
path: "out/Nuget/*.nupkg" | |
- name: Publish Chocolatey | |
uses: actions/upload-artifact@v3 | |
with: | |
name: chocolatey | |
path: "out/Chocolatey/*.nupkg" | |
- name: Publish Portable | |
uses: actions/upload-artifact@v3 | |
with: | |
name: portable | |
path: "out/Portable/*.zip" | |
- name: Publish MSI | |
uses: actions/upload-artifact@v3 | |
with: | |
name: msi | |
path: "out/msi/*" | |
- name: Publish WinGet | |
uses: actions/upload-artifact@v3 | |
with: | |
name: winget | |
path: "out/winget/**" | |
- name: Publish Docs | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docs | |
path: "out/docs/*.zip" | |
- name: Publish Release Notes | |
uses: actions/upload-artifact@v3 | |
with: | |
name: releasenotes | |
path: "docs/ReleaseNotes/**" | |
outputs: | |
BUILD_NAME: ${{ steps.build_module.outputs.BUILD_NAME }} | |
Staging: | |
runs-on: ubuntu-latest | |
environment: staging | |
needs: [ Build ] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BUILD_NAME: ${{ needs.Build.outputs.BUILD_NAME }} | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v3 | |
- name: Extract release notes | |
id: extract_release_notes | |
shell: pwsh | |
run: | | |
$fileName = (Get-ChildItem [0-9]*.md -Recurse | Sort-Object Name | Select -ExpandProperty FullName -Last 1) | |
echo $fileName | |
$releaseNotes = (Get-Content $fileName -Encoding UTF8 | Select-Object -Skip 4) -join '%0A' | |
echo $releaseNotes | |
Write-Output "::set-output name=RELEASE_NOTES::$releaseNotes" | |
- name: Create Draft Release | |
id: create_release | |
shell: pwsh | |
run: | | |
# Install module | |
Install-Module PowerShellForGitHub -Scope CurrentUser -Force | |
# Connect to GitHub | |
Set-GitHubConfiguration -SuppressTelemetryReminder -DefaultOwnerName igoravl -DefaultRepository tfscmdlets | |
$ghCreds = New-Object System.Management.Automation.PSCredential @( "pat", | |
(ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force) | |
) | |
Set-GitHubAuthentication -Credential $ghCreds -SessionOnly | |
# Remove stale draft releases | |
# TODO: Limit scope to this pull request (filter by PR name) | |
Get-GitHubRelease | Where-Object Draft -eq $true | Remove-GitHubRelease -Force | |
# Create new draft releases | |
$release = New-GitHubRelease -Tag 'v${{ env.BUILD_NAME }}' -Name 'Release ${{ env.BUILD_NAME }}' ` | |
-Draft -PreRelease:($env:BUILD_NAME -like '*-*') -commitish '${{ github.sha }}' -Body: @' | |
${{ steps.extract_release_notes.outputs.RELEASE_NOTES }} | |
'@ | |
# Upload assets | |
@('msi/TfsCmdlets*.msi', 'nuget/TfsCmdlets*.nupkg', 'portable/TfsCmdlets*.zip', 'docs/TfsCmdlets*.zip') ` | |
| ForEach-Object { New-GitHubReleaseAsset -Release $release.Id -Path $_ } | |
outputs: | |
BUILD_NAME: ${{ needs.Build.outputs.BUILD_NAME }} | |
RELEASE_NOTES: ${{ steps.extract_release_notes.outputs.RELEASE_NOTES }} | |
Release: | |
runs-on: ubuntu-latest | |
environment: production | |
needs: [ Staging ] | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BUILD_NAME: ${{ needs.Staging.outputs.BUILD_NAME }} | |
steps: | |
- name: Cancel Previous Runs | |
uses: styfle/cancel-workflow-action@0.12.1 | |
with: | |
access_token: ${{ github.token }} | |
- name: Promote release | |
id: promote_release | |
shell: pwsh | |
run: | | |
# Install module | |
Install-Module PowerShellForGitHub -Scope CurrentUser -Force | |
# Connect to GitHub | |
Set-GitHubConfiguration -SuppressTelemetryReminder -DefaultOwnerName igoravl -DefaultRepository tfscmdlets | |
Set-GitHubAuthentication -SessionOnly -Credential (New-Object System.Management.Automation.PSCredential @("pat", | |
(ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force))) | |
# Promote release | |
$rel = Get-GitHubRelease ` | |
| Where-Object { ($_.Draft -eq $true) -and ($_.Name -eq "Release $($env:BUILD_NAME)") } | |
Set-GitHubRelease -Release $rel.id -Draft:$false | |
Write-Output "::set-output name=RELEASE_URL::$($rel.html_url)" | |
Write-Output "::set-output name=RELEASE_TAG::$($env:BUILD_NAME.Replace('+', '%2B'))" | |
outputs: | |
BUILD_NAME: ${{ needs.Staging.outputs.BUILD_NAME }} | |
RELEASE_NOTES: ${{ needs.Staging.outputs.RELEASE_NOTES }} | |
RELEASE_URL: ${{ steps.promote_release.outputs.RELEASE_URL }} | |
RELEASE_TAG: ${{ steps.promote_release.outputs.RELEASE_TAG }} | |
Site: | |
runs-on: ubuntu-latest | |
needs: [ Release ] | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
BUILD_NAME: ${{ needs.Release.outputs.BUILD_NAME }} | |
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
path: site | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: docs | |
- name: Publish site | |
run: | | |
cd site && mkdir docs && pushd docs | |
git checkout --track origin/gh-pages | |
unzip -o ../../TfsCmdlets-Docs-*.zip | |
popd | |
echo build_info: TfsCmdlets v${BUILD_NAME}, released $(date +%F) >> _config.yml | |
echo >> _config.yml | |
git config --local user.name "Igor Abade" | |
git config --local user.email igoravl@gmail.com | |
git add * | |
git commit -m "Publish version $BUILD_NAME" | |
git push | |
PSGallery: | |
runs-on: ubuntu-latest | |
needs: [ Release ] | |
environment: psgallery | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }} | |
PSGALLERY_KEY: ${{ secrets.API_KEY }} | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: portable | |
- name: Publish artifact | |
shell: pwsh | |
run: | | |
Install-Module PackageManagement -Scope CurrentUser -Force | |
Install-Module PowerShellGet -Scope CurrentUser -Force | |
Expand-Archive TfsCmdlets-Portable*.zip -DestinationPath Module/TfsCmdlets | |
$releaseNotes = $env:RELEASE_NOTES | |
Publish-Module -Name Module/TfsCmdlets -NuGetApiKey $env:PSGALLERY_KEY -AllowPreRelease -ReleaseNotes $releaseNotes | |
Nuget: | |
runs-on: ubuntu-latest | |
needs: [ Release ] | |
environment: nuget | |
if: ${{ github.event_name != 'pull_request' }} | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: nuget | |
- name: Install Nuget 5.x | |
uses: nuget/setup-nuget@v1 | |
with: | |
nuget-api-key: ${{ secrets.API_KEY }} | |
nuget-version: '5.x' | |
- name: Push package | |
run: | | |
nuget push $(ls TfsCmdlets*.nupkg) -Source https://api.nuget.org/v3/index.json | |
Chocolatey: | |
runs-on: windows-latest | |
needs: [ Release ] | |
environment: chocolatey | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
CHOCO_KEY: ${{ secrets.API_KEY }} | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: chocolatey | |
- name: Install Chocolatey | |
shell: pwsh | |
run: | | |
Set-ExecutionPolicy Bypass -Scope Process -Force | |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) | |
- name: Push package | |
run: | | |
choco push $(ls TfsCmdlets*.nupkg) --api-key $env:CHOCO_KEY | |
WinGet: | |
runs-on: ubuntu-latest | |
needs: [ Release ] | |
environment: winget | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }} | |
BUILD_NAME: ${{ needs.Release.outputs.BUILD_NAME }} | |
steps: | |
- name: Clone winget-pkgs repository | |
shell: bash | |
run: | | |
git clone --single-branch --branch "master" "https://igoravl:$GITHUB_TOKEN@github.com/igoravl/winget-pkgs.git" | |
cd winget-pkgs | |
git remote add upstream https://github.com/microsoft/winget-pkgs.git | |
git fetch upstream | |
git checkout -b "TfsCmdlets_$BUILD_NAME" | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: winget | |
path: winget-pkgs | |
- name: Push to wingets-pkgs repository | |
shell: bash | |
run: | | |
cd winget-pkgs | |
git config --local user.email "igoravl@gmail.com" | |
git config --local user.name "Igor Abade" | |
git add manifests/i/Igoravl/TfsCmdlets/* | |
git commit -m "Release $BUILD_NAME" | |
git push -u origin "TfsCmdlets_$BUILD_NAME" | |
- name: Create pull request to microsoft/winget-pkgs | |
shell: pwsh | |
run: | | |
# Install module | |
Install-Module PowerShellForGitHub -Scope CurrentUser -Force | |
# Connect to GitHub | |
Set-GitHubConfiguration -SuppressTelemetryReminder -DefaultOwnerName igoravl -DefaultRepository winget-pkgs | |
Set-GitHubAuthentication -SessionOnly -Credential (New-Object System.Management.Automation.PSCredential @("pat", | |
(ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force))) | |
# Create pull request | |
New-GitHubPullRequest -OwnerName Microsoft -RepositoryName winget-pkgs ` | |
-Title "TfsCmdlets_$env:BUILD_NAME" -Head "igoravl:TfsCmdlets_$env:BUILD_NAME" -base master -Body @' | |
- [x] Have you signed the [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs)? | |
- [x] Have you checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change? | |
- [x] Have you validated your manifest locally with `winget validate --manifest <path>`? | |
- [x] Have you tested your manifest locally with `winget install --manifest <path>`? | |
- [x] Does your manifest conform to the [1.0 schema](https://github.com/microsoft/winget-cli/blob/master/doc/ManifestSpecv1.0.md)? | |
Note: `<path>` is the name of the directory containing the manifest you're submitting. | |
----- | |
'@ | |
Announcements: | |
runs-on: ubuntu-latest | |
needs: [ Release, Nuget, PSGallery, Chocolatey, Site, WinGet ] | |
environment: announcements | |
steps: | |
- name: Tweet | |
id: tweet | |
uses: snow-actions/tweet@v1.3.0 | |
env: | |
BUILD_NAME: ${{ needs.Release.outputs.BUILD_NAME }} | |
CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }} | |
CONSUMER_API_SECRET_KEY: ${{ secrets.TWITTER_CONSUMER_API_SECRET_KEY }} | |
ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} | |
ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} | |
RELEASE_TAG: ${{ needs.Release.outputs.RELEASE_TAG }} | |
with: | |
status: | | |
TfsCmdlets version ${{ env.BUILD_NAME }} has just been released. Check it out! https://github.com/igoravl/TfsCmdlets/releases/tag/v${{ env.RELEASE_TAG }} |