From f218a3dda95a8277b169db478f6b4f2cc44fb6b4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 12:36:48 +0200 Subject: [PATCH 01/15] First version --- .github/workflows/Action-Test.yml | 1 - .github/workflows/Auto-Configure.yml | 34 ---------------------------- .github/workflows/Auto-Document.yml | 31 ------------------------- README.md | 17 ++++++++++---- action.yml | 26 +++++++++++---------- scripts/main.ps1 | 16 +++++++++---- scripts/main.sh | 4 ---- 7 files changed, 38 insertions(+), 91 deletions(-) delete mode 100644 .github/workflows/Auto-Configure.yml delete mode 100644 .github/workflows/Auto-Document.yml delete mode 100644 scripts/main.sh diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index c5ce255..11dc744 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -25,4 +25,3 @@ jobs: uses: ./ with: working-directory: ./tests - subject: PSModule diff --git a/.github/workflows/Auto-Configure.yml b/.github/workflows/Auto-Configure.yml deleted file mode 100644 index e2321e4..0000000 --- a/.github/workflows/Auto-Configure.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Auto-Configure - -run-name: "Auto-Configure - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - pull_request_target: - branches: - - main - types: - - closed - - opened - - reopened - - synchronize - - labeled - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: - contents: write # Required to create releases - pull-requests: write # Required to create comments on the PRs - -jobs: - Auto-Configure: - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Auto-Configure - uses: PSModule/Auto-Configure@v1 - env: - GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/Auto-Document.yml b/.github/workflows/Auto-Document.yml deleted file mode 100644 index 6a62053..0000000 --- a/.github/workflows/Auto-Document.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Auto-Document - -run-name: "Auto-Document - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - pull_request_target: - branches: - - main - types: - - opened - - reopened - - synchronize - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: - contents: write # Required to push to the branch - -jobs: - Auto-Document: - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Auto-Document - uses: PSModule/Auto-Document@v1 - env: - GITHUB_TOKEN: ${{ github.token }} diff --git a/README.md b/README.md index 3e74c20..7b67e49 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,26 @@ -# Template-action +# GitHub-Script -A template repository for GitHub Actions +A GitHub Action used for running a PowerShell Script that uses the GitHub PowerShell module ## Usage ### Inputs -### Secrets +| Name | Description | Required | Default | +| - | - | - | - | +| `script` | The path to the script to run | true | | -### Outputs + + + ### Example ```yaml Example here ``` + +### Similar projects + +- [actions/github-script](https://github.com/actions/github-script) + diff --git a/action.yml b/action.yml index 2892a4a..01aea30 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ -name: '{{ NAME }}' -description: '{{ DESCRIPTION }}' +name: GitHub-Script (by PSModule) +description: A GitHub Action used for running a PowerShell Script that uses the GitHub PowerShell module author: PSModule branding: icon: upload-cloud @@ -7,21 +7,23 @@ branding: inputs: working-directory: - description: The working directory where Terraform will be executed + description: The working directory where the script will run from required: false - subject: - description: The subject to greet - required: false - default: World + script: + description: The script to run + required: true runs: using: composite steps: - - name: '{{ NAME }}' + - name: Install GitHub shell: pwsh - working-directory: ${{ inputs.working-directory }} - env: - GITHUB_ACTION_INPUT_subject: ${{ inputs.subject }} run: | - # '{{ NAME }}' + # Install GitHub . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" -Verbose + + - name: GitHub-Script + shell: pwsh + working-directory: ${{ inputs.working-directory }} + run: | + ${{ inputs.script }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b054fcc..a991bf8 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,7 +1,13 @@ [CmdletBinding()] -param( - [Parameter()] - [string] $Subject = $env:GITHUB_ACTION_INPUT_subject -) +param() -Write-Host "Hello, $subject!" +Write-Host '::group::Install GitHub' +$params = @{ + Name = 'GitHub' + Repository = 'PSGallery' + TrustRepository = $true + Verbose = $true +} +Install-PSResource @params +Import-Module -Name 'GitHub' -Force -Verbose +Write-Host '::endgroup::' diff --git a/scripts/main.sh b/scripts/main.sh deleted file mode 100644 index 8589a85..0000000 --- a/scripts/main.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# Run 'git add --chmod=+x scripts\main.sh' to make the script executable - -echo "Hello, $SUBJECT!" From ad6e40231de7b533dcedd57c9484a53a029dd74c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 12:43:13 +0200 Subject: [PATCH 02/15] Comments --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b67e49..1f2a774 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,22 @@ A GitHub Action used for running a PowerShell Script that uses the GitHub PowerS | - | - | - | - | | `script` | The path to the script to run | true | | + + + + ### Example @@ -22,5 +36,6 @@ Example here ### Similar projects +- [actions/create-github-app-token](https://github.com/actions/create-github-app-token) -> Functionality will be brought into GitHub PowerShell module. - [actions/github-script](https://github.com/actions/github-script) - +- [PSModule/GitHub](https://github.com/PSModule/GitHub) From 9b9fc7295aa67b89442da5fb08c70fc8a72a9683 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 12:59:50 +0200 Subject: [PATCH 03/15] test --- action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/action.yml b/action.yml index 01aea30..c43e76f 100644 --- a/action.yml +++ b/action.yml @@ -12,12 +12,18 @@ inputs: script: description: The script to run required: true + token: + description: The GitHub token to use + required: false + default: ${{ github.token }} runs: using: composite steps: - name: Install GitHub shell: pwsh + env: + GITHUB_TOKEN: ${{ inputs.token }} run: | # Install GitHub . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" -Verbose From d8855338df02d63f53761460c3f7132fd097bbd9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 13:01:02 +0200 Subject: [PATCH 04/15] test --- .github/workflows/Action-Test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 11dc744..6f1b792 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -24,4 +24,6 @@ jobs: - name: Action-Test uses: ./ with: - working-directory: ./tests + script: | + Get-GitHubZen + Get-GitHubRepository From 0e7a621f554e8a1db68727f66253acb6ff7bcd69 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 18:24:33 +0200 Subject: [PATCH 05/15] Fix linting --- .github/workflows/Action-Test.yml | 59 +++++++++++++------------- .github/workflows/Auto-Release.yml | 68 +++++++++++++++--------------- .github/workflows/Linter.yml | 60 +++++++++++++------------- 3 files changed, 95 insertions(+), 92 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 6f1b792..a05e7f5 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -1,29 +1,30 @@ -name: Action-Test - -run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: [pull_request] - -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: ./ - with: - script: | - Get-GitHubZen - Get-GitHubRepository +name: Action-Test + +run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" + +on: [pull_request] + +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: ./ + with: + script: | + LogGroup "Test-PSModule" { + Get-GitHubZen + } diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index d6c477b..1a580b8 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -1,34 +1,34 @@ -name: Auto-Release - -run-name: "Auto-Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - pull_request_target: - branches: - - main - types: - - closed - - opened - - reopened - - synchronize - - labeled - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: - contents: write # Required to create releases - pull-requests: write # Required to create comments on the PRs - -jobs: - Auto-Release: - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Auto-Release - uses: PSModule/Auto-Release@v1 - env: - GITHUB_TOKEN: ${{ github.token }} +name: Auto-Release + +run-name: "Auto-Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" + +on: + pull_request_target: + branches: + - main + types: + - closed + - opened + - reopened + - synchronize + - labeled + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write # Required to create releases + pull-requests: write # Required to create comments on the PRs + +jobs: + Auto-Release: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Auto-Release + uses: PSModule/Auto-Release@v1 + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 187c17e..c02889b 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -1,29 +1,31 @@ -name: Linter - -run-name: "Linter - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: [pull_request] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: - contents: read - packages: read - statuses: write - -jobs: - Lint: - name: Lint code base - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Lint code base - uses: super-linter/super-linter/slim@latest - env: - GITHUB_TOKEN: ${{ github.token }} +name: Linter + +run-name: "Linter - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" + +on: [pull_request] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + packages: read + statuses: write + +jobs: + Lint: + name: Lint code base + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Lint code base + uses: super-linter/super-linter/slim@latest + env: + GITHUB_TOKEN: ${{ github.token }} + VALIDATE_MARKDOWN_PRETTIER: false + VALIDATE_YAML_PRETTIER: false From bcd72c9ab2f5cbb9280a5e90e1c12ea9c1181ee8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 18:26:31 +0200 Subject: [PATCH 06/15] test --- action.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/action.yml b/action.yml index c43e76f..80619bf 100644 --- a/action.yml +++ b/action.yml @@ -22,14 +22,10 @@ runs: steps: - name: Install GitHub shell: pwsh + working-directory: ${{ inputs.working-directory }} env: GITHUB_TOKEN: ${{ inputs.token }} run: | # Install GitHub . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" -Verbose - - - name: GitHub-Script - shell: pwsh - working-directory: ${{ inputs.working-directory }} - run: | ${{ inputs.script }} From 403726fcea877321a6142e7e6c5fda2eb2027435 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 18:34:48 +0200 Subject: [PATCH 07/15] test --- action.yml | 3 ++- scripts/main.ps1 | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 80619bf..f3fdf87 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,7 @@ runs: env: GITHUB_TOKEN: ${{ inputs.token }} run: | - # Install GitHub + # GitHub-Script . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" -Verbose + ${{ inputs.script }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a991bf8..0a3113c 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,13 +1,10 @@ [CmdletBinding()] param() -Write-Host '::group::Install GitHub' $params = @{ Name = 'GitHub' Repository = 'PSGallery' TrustRepository = $true - Verbose = $true } Install-PSResource @params -Import-Module -Name 'GitHub' -Force -Verbose -Write-Host '::endgroup::' +Import-Module -Name 'GitHub' -Force From 351b5ee89d5b1e539a2e5643488a7cae6a3cb04e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 18:38:36 +0200 Subject: [PATCH 08/15] Fix --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f3fdf87..01b3a22 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,6 @@ runs: GITHUB_TOKEN: ${{ inputs.token }} run: | # GitHub-Script - . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" -Verbose + . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" ${{ inputs.script }} From b0c4f56fb48d1d20f4f259bafe21ee2b35b400c9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Aug 2024 18:59:21 +0200 Subject: [PATCH 09/15] test --- .github/workflows/Action-Test.yml | 9 ++++++ README.md | 6 +++- action.yml | 48 +++++++++++++++++++++++++------ scripts/main.ps1 | 10 ++++++- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index a05e7f5..5853f21 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -28,3 +28,12 @@ jobs: LogGroup "Test-PSModule" { Get-GitHubZen } + + - name: Action-Test 2 + uses: ./ + with: + Verbose: true + script: | + LogGroup "Test-PSModule" { + Get-GitHubZen + } diff --git a/README.md b/README.md index 1f2a774..a2b533a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,11 @@ A GitHub Action used for running a PowerShell Script that uses the GitHub PowerS | Name | Description | Required | Default | | - | - | - | - | -| `script` | The path to the script to run | true | | +| `Script` | The script to run | true | | +| `Token` | The GitHub token to use | false | ${{ github.token }} | +| `Debug` | Enable debug output | false | 'false' | +| `Verbose` | Enable verbose output | false | 'false' | +| `WorkingDirectory` | The working directory where the script will run from | false | ${{ github.workspace }} |