diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 72445dd..77b6918 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -17,168 +17,12 @@ permissions: pull-requests: read jobs: - ActionTestBasic: - name: Action-Test - [Basic] - runs-on: ubuntu-latest - steps: - # Need to check out as part of the test, as its a local action - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - with: - Debug: true - Verbose: true - - ActionTestWithScript: - name: Action-Test - [WithScript] - runs-on: ubuntu-latest - steps: - # Need to check out as part of the test, as its a local action - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - with: - Debug: true - Verbose: true - Script: | - LogGroup 'Get-GitHubZen' { - Get-GitHubZen - } - - LogGroup 'Get-GitHubViewer' { - Get-GitHubViewer -Fields name, login, id, databaseID - } - - ActionTestCommands: - name: Action-Test - [Commands] - runs-on: ubuntu-latest - steps: - # Need to check out as part of the test, as its a local action - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - id: test - with: - Debug: true - Verbose: true - Prerelease: true - ShowOutput: true - Script: | - $cat = Get-GitHubOctocat - $zen = Get-GitHubZen - Set-GitHubEnvironmentVariable -Name 'OCTOCAT' -Value $cat - Set-GitHubOutput -Name 'WISECAT' -Value $cat - Set-GitHubOutput -Name 'Zen' -Value $zen - - - name: Run-test - shell: pwsh - env: - result: ${{ steps.test.outputs.result }} - WISECAT: ${{ fromJson(steps.test.outputs.result).WISECAT }} - run: | - $result = $env:result | ConvertFrom-Json - Set-GitHubStepSummary -Summary $env:WISECAT - Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen' - - ActionTestWithoutToken: - name: Action-Test - [WithoutToken] - runs-on: ubuntu-latest - steps: - # Need to check out as part of the test, as its a local action - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - with: - Token: '' - Script: | - LogGroup 'My group' { - 'This is a group' - } - - ActionTestWithPAT: - name: Action-Test - [WithPAT] - runs-on: ubuntu-latest - steps: - # Need to check out as part of the test, as its a local action - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - with: - Token: ${{ secrets.TEST_USER_PAT }} - Script: | - LogGroup 'Get-GitHubUser' { - Get-GitHubUser | Format-Table -AutoSize - } - - ActionTestWithFGPAT: + ActionTest: + uses: ./.github/workflows/TestWorkflow.yml + secrets: inherit strategy: + fail-fast: false matrix: - include: - - name: Action-Test - [WithUserFGPAT] - Token: TEST_USER_USER_FG_PAT - - name: Action-Test - [WithOrgFGPAT] - Token: TEST_USER_ORG_FG_PAT - name: ${{ matrix.name }} - runs-on: ubuntu-latest - steps: - # Need to check out as part of the test, as its a local action - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - with: - Token: ${{ secrets[matrix.Token] }} - Script: | - LogGroup 'Get-GitHubUser' { - Get-GitHubUser | Format-Table -AutoSize - } - - ActionTestWithGitHubApp: - strategy: - matrix: - include: - - name: Action-Test - [GitHubAppEnt] - clientID: TEST_APP_ENT_CLIENT_ID - privateKey: TEST_APP_ENT_PRIVATE_KEY - - name: Action-Test - [GitHubAppOrg] - clientID: TEST_APP_ORG_CLIENT_ID - privateKey: TEST_APP_ORG_PRIVATE_KEY - name: ${{ matrix.name }} - runs-on: ubuntu-latest - steps: - # Need to check out as part of the test, as its a local action - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - with: - ClientID: ${{ secrets[matrix.clientID] }} - PrivateKey: ${{ secrets[matrix.privateKey] }} - Script: | - LogGroup 'Get-GitHubApp' { - Get-GitHubApp | Format-Table -AutoSize - } - - LogGroup 'Get-GitHubAppInstallation' { - Get-GitHubAppInstallation | Format-Table -AutoSize - } - - LogGroup 'Do something as an installation' { - Get-GithubAppInstallation | New-GitHubAppInstallationAccessToken | ForEach-Object { - Connect-GitHub -Token $_.token -Silent - Get-GitHubContext | Format-Table -AutoSize - Get-GitHubGitConfig | Format-Table -AutoSize - } - } + os: [ubuntu-latest, macos-latest, windows-latest] + with: + runs-on: ${{ matrix.os }} diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index c02889b..9477fd5 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -29,3 +29,4 @@ jobs: GITHUB_TOKEN: ${{ github.token }} VALIDATE_MARKDOWN_PRETTIER: false VALIDATE_YAML_PRETTIER: false + VALIDATE_JSCPD: false diff --git a/.github/workflows/TestWorkflow.yml b/.github/workflows/TestWorkflow.yml new file mode 100644 index 0000000..9823eb8 --- /dev/null +++ b/.github/workflows/TestWorkflow.yml @@ -0,0 +1,239 @@ +on: + workflow_call: + inputs: + runs-on: + description: 'The operating system to run the tests on' + required: true + type: string + secrets: + TEST_USER_PAT: + description: 'Personal Access Token for the test user' + required: true + TEST_USER_USER_FG_PAT: + description: 'Personal Access Token for the test user with full gists scope' + required: true + TEST_USER_ORG_FG_PAT: + description: 'Personal Access Token for the test user with full gists scope' + required: true + TEST_APP_ENT_CLIENT_ID: + description: 'Client ID for the test GitHub App for the enterprise' + required: true + TEST_APP_ENT_PRIVATE_KEY: + description: 'Private Key for the test GitHub App for the enterprise' + required: true + TEST_APP_ORG_CLIENT_ID: + description: 'Client ID for the test GitHub App for the organization' + required: true + TEST_APP_ORG_PRIVATE_KEY: + description: 'Private Key for the test GitHub App for the organization' + required: true + +permissions: + contents: read + pull-requests: read + +jobs: + ActionTestBasic: + name: Basic + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + Debug: true + Verbose: true + + ActionTestWithScript: + name: WithScript + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + Debug: true + Verbose: true + Script: | + LogGroup 'Get-GitHubZen' { + Get-GitHubZen + } + + LogGroup 'Get-GitHubViewer' { + Get-GitHubViewer -Fields name, login, id, databaseID + } + + ActionTestCommands: + name: Commands + Outputs + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + id: test + with: + Debug: true + Verbose: true + Prerelease: true + ShowOutput: true + Script: | + LogGroup 'Get-GitHubZen' { + $cat = Get-GitHubOctocat + $zen = Get-GitHubZen + Set-GitHubEnvironmentVariable -Name 'OCTOCAT' -Value $cat + } + + LogGroup 'Set outputs WISECAT' { + Set-GitHubOutput -Name 'WISECAT' -Value $cat + } + + LogGroup 'Set outputs Zen' { + Set-GitHubOutput -Name 'Zen' -Value $zen + } + + - name: Run-test + shell: pwsh + env: + result: ${{ steps.test.outputs.result }} + WISECAT: ${{ fromJson(steps.test.outputs.result).WISECAT }} + run: | + $result = $env:result | ConvertFrom-Json + Set-GitHubStepSummary -Summary $env:WISECAT + Write-GitHubNotice -Message $result.Zen -Title 'GitHub Zen' + + ActionTestWithoutToken: + name: WithoutToken + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + Token: '' + Script: | + LogGroup 'My group' { + 'This is a group' + } + + ActionTestWithPAT: + name: WithPAT + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + Token: ${{ secrets.TEST_USER_PAT }} + Script: | + LogGroup 'Get-GitHubUser' { + Get-GitHubUser | Format-Table -AutoSize + } + + ActionTestWithUSERFGPAT: + name: WithUserFGPAT + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + Token: ${{ secrets.TEST_USER_USER_FG_PAT }} + Script: | + LogGroup 'Get-GitHubUser' { + Get-GitHubUser | Format-Table -AutoSize + } + + ActionTestWithORGFGPAT: + name: WithOrgFGPAT + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + Token: ${{ secrets.TEST_USER_ORG_FG_PAT }} + Script: | + LogGroup 'Get-GitHubUser' { + Get-GitHubUser | Format-Table -AutoSize + } + + ActionTestWithGitHubAppEnt: + name: GitHubAppEnt + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + ClientID: ${{ secrets.TEST_APP_ENT_CLIENT_ID }} + PrivateKey: ${{ secrets.TEST_APP_ENT_PRIVATE_KEY }} + Script: | + LogGroup 'Get-GitHubApp' { + Get-GitHubApp | Format-Table -AutoSize + } + + LogGroup 'Get-GitHubAppInstallation' { + Get-GitHubAppInstallation | Format-Table -AutoSize + } + + LogGroup 'Do something as an installation' { + Get-GithubAppInstallation | New-GitHubAppInstallationAccessToken | ForEach-Object { + Connect-GitHub -Token $_.token -Silent + Get-GitHubContext | Format-Table -AutoSize + Get-GitHubGitConfig | Format-Table -AutoSize + } + } + + ActionTestWithGitHubAppOrg: + name: GitHubAppOrg + runs-on: ${{ inputs.runs-on }} + steps: + # Need to check out as part of the test, as its a local action + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + with: + ClientID: ${{ secrets.TEST_APP_ORG_CLIENT_ID }} + PrivateKey: ${{ secrets.TEST_APP_ORG_PRIVATE_KEY }} + Script: | + LogGroup 'Get-GitHubApp' { + Get-GitHubApp | Format-Table -AutoSize + } + + LogGroup 'Get-GitHubAppInstallation' { + Get-GitHubAppInstallation | Format-Table -AutoSize + } + + LogGroup 'Do something as an installation' { + Get-GithubAppInstallation | New-GitHubAppInstallationAccessToken | ForEach-Object { + Connect-GitHub -Token $_.token -Silent + Get-GitHubContext | Format-Table -AutoSize + Get-GitHubGitConfig | Format-Table -AutoSize + } + } diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 95b46bf..815502a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,11 +1,8 @@ [CmdletBinding()] param() -$Host.UI.RawUI.WindowSize.Width = 500 -$Host.UI.RawUI.BufferSize.Width = 500 - $env:PSMODULE_GITHUB_SCRIPT = $true -Write-Host "┏━━━━━┫ GitHub-Script ┣━━━━━┓" +Write-Host '┏━━━━━┫ GitHub-Script ┣━━━━━┓' Write-Host '::group:: - Setup GitHub PowerShell' $Name = 'GitHub' @@ -33,7 +30,19 @@ if (-not $alreadyInstalled) { if ($Version) { $params['Version'] = $Version } - Install-PSResource @params + $Count = 5 + $Delay = 10 + for ($i = 0; $i -lt $Count; $i++) { + try { + Install-PSResource @params + break + } catch { + if ($i -eq $Count - 1) { + throw $_ + } + Start-Sleep -Seconds $Delay + } + } } $alreadyImported = Get-Module -Name $Name