From df60b7a7d906a734d61d1965d2b37aaf80ed7ed7 Mon Sep 17 00:00:00 2001 From: Bernie White Date: Mon, 27 Feb 2023 18:53:13 +1000 Subject: [PATCH] Add release branches #214 (#215) --- .github/workflows/build.yaml | 97 ++++++++++++++--------------- .github/workflows/dependencies.yaml | 3 +- .github/workflows/release.yaml | 58 +++++++++++++++++ .github/workflows/stale.yaml | 29 +++++---- README.md | 14 +++++ docs/CHANGELOG-v2.md | 6 ++ scripts/branches.psm1 | 56 +++++++++++++++++ 7 files changed, 196 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 scripts/branches.psm1 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c663651..6efccb2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,52 +2,50 @@ name: Build on: push: - branches: [ main, 'release/*' ] + branches: [main, 'release/*'] pull_request: - branches: [ main, 'release/*' ] + branches: [main, 'release/*'] jobs: - test: - name: 'Tests' + name: Tests runs-on: ubuntu-latest permissions: contents: read steps: + - name: Checkout + uses: actions/checkout@v3 - - name: Checkout - uses: actions/checkout@v3 + - name: Register repository + shell: pwsh + run: |- + $Null = New-Item -Path out/repo -Type Directory -Force; - - name: Register repository - shell: pwsh - run: |- - $Null = New-Item -Path out/repo -Type Directory -Force; + Invoke-WebRequest -Uri 'https://www.powershellgallery.com/api/v2/package/PSRule/1.11.1' -OutFile out/repo/PSRule.1.11.1.nupkg; + Invoke-WebRequest -Uri 'https://www.powershellgallery.com/api/v2/package/PSRule.Rules.MSFT.OSS/1.0.1' -OutFile out/repo/PSRule.Rules.MSFT.OSS.1.0.1.nupkg; + Save-Module -Name PSRule.Rules.MSFT.OSS -Repository PSGallery -Path out/repo/; + Register-PSRepository -SourceLocation out/repo -Name Local -InstallationPolicy Trusted; - Invoke-WebRequest -Uri 'https://www.powershellgallery.com/api/v2/package/PSRule/1.11.1' -OutFile out/repo/PSRule.1.11.1.nupkg; - Invoke-WebRequest -Uri 'https://www.powershellgallery.com/api/v2/package/PSRule.Rules.MSFT.OSS/1.0.1' -OutFile out/repo/PSRule.Rules.MSFT.OSS.1.0.1.nupkg; - Save-Module -Name PSRule.Rules.MSFT.OSS -Repository PSGallery -Path out/repo/; - Register-PSRepository -SourceLocation out/repo -Name Local -InstallationPolicy Trusted; + - name: Run PSRule v1 + uses: ./ + with: + inputType: repository + modules: PSRule.Rules.MSFT.OSS + repository: Local + version: '1.11.1' - - name: Run PSRule v1 - uses: ./ - with: - inputType: repository - modules: PSRule.Rules.MSFT.OSS - repository: Local - version: '1.11.1' + - name: Run PSRule v2 + uses: ./ + with: + inputType: repository + modules: PSRule.Rules.MSFT.OSS + outcome: Problem - - name: Run PSRule v2 - uses: ./ - with: - inputType: repository - modules: PSRule.Rules.MSFT.OSS - outcome: Problem - - - name: Unregister repository - shell: pwsh - if: always() - run: |- - Unregister-PSRepository -Name Local -ErrorAction Ignore; + - name: Unregister repository + shell: pwsh + if: always() + run: |- + Unregister-PSRepository -Name Local -ErrorAction Ignore; run: name: Analyze repository @@ -56,22 +54,21 @@ jobs: permissions: contents: read steps: + - name: Checkout + uses: actions/checkout@v3 - - name: Checkout - uses: actions/checkout@v3 + - name: Run PSRule self analysis + uses: ./ + with: + inputType: repository + outputFormat: Markdown + outputPath: reports/report.md + modules: PSRule.Rules.MSFT.OSS + prerelease: true - - name: Run PSRule self analysis - uses: ./ - with: - inputType: repository - outputFormat: Markdown - outputPath: reports/report.md - modules: PSRule.Rules.MSFT.OSS - prerelease: true - - - name: PSRule results - uses: actions/upload-artifact@v3 - if: always() - with: - name: PSRule-results - path: reports/report.md + - name: PSRule results + uses: actions/upload-artifact@v3 + if: always() + with: + name: PSRule-results + path: reports/report.md diff --git a/.github/workflows/dependencies.yaml b/.github/workflows/dependencies.yaml index ff62fe7..1c8d222 100644 --- a/.github/workflows/dependencies.yaml +++ b/.github/workflows/dependencies.yaml @@ -8,7 +8,7 @@ name: Dependencies on: schedule: - - cron: '50 1 * * 1' # At 01:50 AM, on Monday each week + - cron: '50 1 * * 1' # At 01:50 AM, on Monday each week workflow_dispatch: env: @@ -23,7 +23,6 @@ jobs: contents: write pull-requests: write steps: - - name: Checkout uses: actions/checkout@v3 with: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..fad6999 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,58 @@ +# +# Automated updates for release branches +# + +# NOTES: +# This automatically bumps release branches to the latest stable tag. + +name: Release + +on: + release: + types: + - created + - deleted + workflow_dispatch: + inputs: + major: + type: choice + description: Determines the release branch to bump. + required: true + options: + - 'v1' + - 'v2' + default: v2 + +env: + RELEASE_BRANCH: ${{ inputs.major | 'v2' }} + LATEST_BRANCH: v2 + +permissions: + contents: read + +jobs: + branch: + name: Update release branch + runs-on: ubuntu-latest + if: github.repository == 'microsoft/ps-rule' + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure + run: | + git config user.name github-actions + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' + + - name: Push release branch + run: | + Import-Module ./scripts/branches.psm1; + $latest = '${{ env.RELEASE_BRANCH }}' -eq '${{ env.LATEST_BRANCH }}'; + Update-Branch -Remote origin -Major ${{ env.RELEASE_BRANCH }} -Latest:$latest; + shell: pwsh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/stale.yaml b/.github/workflows/stale.yaml index f4a79a2..3bbec57 100644 --- a/.github/workflows/stale.yaml +++ b/.github/workflows/stale.yaml @@ -10,7 +10,7 @@ name: 'Close stale issues' on: schedule: - - cron: '30 1 * * *' # At 1:30 AM, daily + - cron: '30 1 * * *' # At 1:30 AM, daily jobs: stale: @@ -19,21 +19,20 @@ jobs: issues: write pull-requests: write steps: + - uses: actions/stale@v7 + with: + stale-issue-message: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs within 7 days. + Thank you for your contributions. - - uses: actions/stale@v7 - with: - stale-issue-message: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs within 7 days. - Thank you for your contributions. + close-issue-message: 'This issue was closed because it has not had any recent activity.' - close-issue-message: 'This issue was closed because it has not had any recent activity.' + days-before-stale: 14 + days-before-pr-stale: -1 - days-before-stale: 14 - days-before-pr-stale: -1 + days-before-close: 7 + days-before-pr-close: -1 - days-before-close: 7 - days-before-pr-close: -1 - - any-of-labels: 'question,duplicate,incomplete,waiting-feedback' - stale-issue-label: stale + any-of-labels: 'question,duplicate,incomplete,waiting-feedback' + stale-issue-label: stale diff --git a/README.md b/README.md index 0b180bb..c8a643a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,20 @@ To learn about PSRule and how to write your own rules see [Getting started][1]. To get the latest stable release use: +```yaml +- name: Run PSRule analysis + uses: microsoft/ps-rule@latest +``` + +To get the latest stable release by major version use: + +```yaml +- name: Run PSRule analysis + uses: microsoft/ps-rule@v2 +``` + +To get a specific release use: + ```yaml - name: Run PSRule analysis uses: microsoft/ps-rule@v2.7.0 diff --git a/docs/CHANGELOG-v2.md b/docs/CHANGELOG-v2.md index 339a9ff..4f50d46 100644 --- a/docs/CHANGELOG-v2.md +++ b/docs/CHANGELOG-v2.md @@ -6,6 +6,12 @@ See [upgrade notes][upgrade-notes] for helpful information when upgrading from p ## Unreleased +What's changed since v2.8.0: + +- General improvements: + - Added support for action release branches by @BernieWhite. + [#214](https://github.com/microsoft/ps-rule/issues/214) + ## v2.7.0 What's changed since v2.6.0: diff --git a/scripts/branches.psm1 b/scripts/branches.psm1 new file mode 100644 index 0000000..0b7169b --- /dev/null +++ b/scripts/branches.psm1 @@ -0,0 +1,56 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# Note: +# Handles bump to release branches. + +function Update-Branch { + [CmdletBinding()] + [OutputType([void])] + param ( + [Parameter(Mandatory = $True)] + [String]$Major, + + [Parameter(Mandatory = $True)] + [String]$Remote, + + [Parameter(Mandatory = $False)] + [Switch]$Latest + ) + process { + $latest = Get-LatestVersion -Remote $Remote -Major $Major; + + Write-Host "Latest stable release is: $latest"; + Write-Host "Checking out tag for: $latest" + + git fetch --tags $Remote; + git checkout refs/tags/v$latest; + + Write-Host "Updating release branch: $Major"; + git push $Remote refs/tags/v$latest`:refs/heads/$Major --force; + + if ($Latest) { + Write-Host "Updating latest to: $Major"; + git push $Remote refs/tags/v$latest`:refs/heads/latest --force; + } + + git checkout main; + } +} + +function Get-LatestVersion { + [CmdletBinding()] + [OutputType([String])] + param ( + [Parameter(Mandatory = $True)] + [String]$Major, + + [Parameter(Mandatory = $True)] + [String]$Remote + ) + process { + return (gh api repos/microsoft/ps-rule/releases | Out-String | ConvertFrom-Json | Where-Object { + $_.prerelease -eq $False -and $_.name -like "$Major.*" + } | Select-Object -Property @{ Name = 'version'; Expression = { [System.Version]::Parse($_.name.Replace('v', '')) } } | Sort-Object -Property version -Descending -Top 1).Version.ToString(); + } +}