Action-Test - [ #] by @MariusStorhaug #145
Workflow file for this run
This file contains hidden or 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: Action-Test | |
| run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| 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: ./ | |
| 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: | |
| Script: | | |
| $context = Get-GitHubContext | |
| # GraphQL Endpoint | |
| $GraphQLEndpoint = 'https://api.github.com/graphql' | |
| # Headers | |
| $Headers = @{ | |
| 'Content-Type' = 'application/json' | |
| } | |
| # GraphQL Query for fetching user's organizations and repositories | |
| $Query = @' | |
| { | |
| viewer { | |
| enterprises(first: 100) { | |
| nodes { | |
| name | |
| slug | |
| id | |
| } | |
| } | |
| organizations(first: 100) { | |
| nodes { | |
| name | |
| login | |
| url | |
| } | |
| } | |
| repositories(first: 100, privacy: PUBLIC) { | |
| nodes { | |
| name | |
| url | |
| isPrivate | |
| } | |
| } | |
| } | |
| } | |
| '@ | |
| # Prepare the body for the HTTP POST | |
| $Body = @{ | |
| query = $Query | |
| } | ConvertTo-Json -Depth 10 | |
| # Make the HTTP POST request | |
| $response = Invoke-RestMethod -Uri $GraphQLEndpoint -Headers $Headers -Method Post -Body $Body -Token $context.Token -Authentication Bearer | |
| # Process the response | |
| if ($response) { | |
| Write-Output "User Login: $($response.data.viewer.login)" | |
| Write-Output 'Enterprises:' | |
| $response.data.viewer.enterprises.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), Slug: $($_.slug), ID: $($_.id)" | |
| } | |
| Write-Output 'Organizations:' | |
| $response.data.viewer.organizations.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), Login: $($_.login), URL: $($_.url)" | |
| if ($_.enterprise -ne $null) { | |
| Write-Output " Enterprise: $($_.enterprise.name), URL: $($_.enterprise.url)" | |
| } | |
| } | |
| Write-Output 'Repositories:' | |
| $response.data.viewer.repositories.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), URL: $($_.url), Private: $($_.isPrivate)" | |
| } | |
| } else { | |
| Write-Error 'Failed to fetch data from GitHub API.' | |
| } | |
| 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: | |
| Prerelease: 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 }} | |
| run: | | |
| $result = $env:result | ConvertFrom-Json | |
| Set-GitHubStepSummary -Summary $result.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_PAT }} | |
| Script: | | |
| $context = Get-GitHubContext | |
| # GraphQL Endpoint | |
| $GraphQLEndpoint = 'https://api.github.com/graphql' | |
| # Headers | |
| $Headers = @{ | |
| 'Content-Type' = 'application/json' | |
| } | |
| # GraphQL Query for fetching user's organizations and repositories | |
| $Query = @' | |
| { | |
| viewer { | |
| enterprises(first: 100) { | |
| nodes { | |
| name | |
| slug | |
| id | |
| } | |
| } | |
| organizations(first: 100) { | |
| nodes { | |
| name | |
| login | |
| url | |
| } | |
| } | |
| repositories(first: 100, privacy: PUBLIC) { | |
| nodes { | |
| name | |
| url | |
| isPrivate | |
| } | |
| } | |
| } | |
| } | |
| '@ | |
| # Prepare the body for the HTTP POST | |
| $Body = @{ | |
| query = $Query | |
| } | ConvertTo-Json -Depth 10 | |
| # Make the HTTP POST request | |
| $response = Invoke-RestMethod -Uri $GraphQLEndpoint -Headers $Headers -Method Post -Body $Body -Token $context.Token -Authentication Bearer | |
| # Process the response | |
| if ($response) { | |
| Write-Output "User Login: $($response.data.viewer.login)" | |
| Write-Output 'Enterprises:' | |
| $response.data.viewer.enterprises.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), Slug: $($_.slug), ID: $($_.id)" | |
| } | |
| Write-Output 'Organizations:' | |
| $response.data.viewer.organizations.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), Login: $($_.login), URL: $($_.url)" | |
| if ($_.enterprise -ne $null) { | |
| Write-Output " Enterprise: $($_.enterprise.name), URL: $($_.enterprise.url)" | |
| } | |
| } | |
| Write-Output 'Repositories:' | |
| $response.data.viewer.repositories.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), URL: $($_.url), Private: $($_.isPrivate)" | |
| } | |
| } else { | |
| Write-Error 'Failed to fetch data from GitHub API.' | |
| } | |
| ActionTestWithFGPAT: | |
| name: Action-Test - [WithFGPAT] | |
| 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_FG_PAT }} | |
| Script: | | |
| $context = Get-GitHubContext | |
| # GraphQL Endpoint | |
| $GraphQLEndpoint = 'https://api.github.com/graphql' | |
| # Headers | |
| $Headers = @{ | |
| 'Content-Type' = 'application/json' | |
| } | |
| # GraphQL Query for fetching user's organizations and repositories | |
| $Query = @' | |
| { | |
| viewer { | |
| enterprises(first: 100) { | |
| nodes { | |
| name | |
| slug | |
| id | |
| } | |
| } | |
| organizations(first: 100) { | |
| nodes { | |
| name | |
| login | |
| url | |
| } | |
| } | |
| repositories(first: 100, privacy: PUBLIC) { | |
| nodes { | |
| name | |
| url | |
| isPrivate | |
| } | |
| } | |
| } | |
| } | |
| '@ | |
| # Prepare the body for the HTTP POST | |
| $Body = @{ | |
| query = $Query | |
| } | ConvertTo-Json -Depth 10 | |
| # Make the HTTP POST request | |
| $response = Invoke-RestMethod -Uri $GraphQLEndpoint -Headers $Headers -Method Post -Body $Body -Token $context.Token -Authentication Bearer | |
| # Process the response | |
| if ($response) { | |
| Write-Output "User Login: $($response.data.viewer.login)" | |
| Write-Output 'Enterprises:' | |
| $response.data.viewer.enterprises.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), Slug: $($_.slug), ID: $($_.id)" | |
| } | |
| Write-Output 'Organizations:' | |
| $response.data.viewer.organizations.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), Login: $($_.login), URL: $($_.url)" | |
| if ($_.enterprise -ne $null) { | |
| Write-Output " Enterprise: $($_.enterprise.name), URL: $($_.enterprise.url)" | |
| } | |
| } | |
| Write-Output 'Repositories:' | |
| $response.data.viewer.repositories.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), URL: $($_.url), Private: $($_.isPrivate)" | |
| } | |
| } else { | |
| Write-Error 'Failed to fetch data from GitHub API.' | |
| } | |
| ActionTestWithGitHubApp: | |
| name: Action-Test - [GitHubApp] | |
| 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.TEST_APP_CLIENT_ID }} | |
| PrivateKey: ${{ secrets.TEST_APP_PRIVATE_KEY }} | |
| Script: | | |
| $context = Get-GitHubContext | |
| # GraphQL Endpoint | |
| $GraphQLEndpoint = 'https://api.github.com/graphql' | |
| # Headers | |
| $Headers = @{ | |
| 'Content-Type' = 'application/json' | |
| } | |
| # GraphQL Query for fetching user's organizations and repositories | |
| $Query = @' | |
| { | |
| viewer { | |
| enterprises(first: 100) { | |
| nodes { | |
| name | |
| slug | |
| id | |
| } | |
| } | |
| organizations(first: 100) { | |
| nodes { | |
| name | |
| login | |
| url | |
| } | |
| } | |
| repositories(first: 100, privacy: PUBLIC) { | |
| nodes { | |
| name | |
| url | |
| isPrivate | |
| } | |
| } | |
| } | |
| } | |
| '@ | |
| # Prepare the body for the HTTP POST | |
| $Body = @{ | |
| query = $Query | |
| } | ConvertTo-Json -Depth 10 | |
| # Make the HTTP POST request | |
| $response = Invoke-RestMethod -Uri $GraphQLEndpoint -Headers $Headers -Method Post -Body $Body -Token $context.Token -Authentication Bearer | |
| # Process the response | |
| if ($response) { | |
| Write-Output "User Login: $($response.data.viewer.login)" | |
| Write-Output 'Enterprises:' | |
| $response.data.viewer.enterprises.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), Slug: $($_.slug), ID: $($_.id)" | |
| } | |
| Write-Output 'Organizations:' | |
| $response.data.viewer.organizations.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), Login: $($_.login), URL: $($_.url)" | |
| if ($_.enterprise -ne $null) { | |
| Write-Output " Enterprise: $($_.enterprise.name), URL: $($_.enterprise.url)" | |
| } | |
| } | |
| Write-Output 'Repositories:' | |
| $response.data.viewer.repositories.nodes | ForEach-Object { | |
| Write-Output " - Name: $($_.name), URL: $($_.url), Private: $($_.isPrivate)" | |
| } | |
| } else { | |
| Write-Error 'Failed to fetch data from GitHub API.' | |
| } |