diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index c5ce255..5853f21 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -1,28 +1,39 @@ -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: - working-directory: ./tests - subject: PSModule +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 + } + + - name: Action-Test 2 + uses: ./ + with: + Verbose: true + script: | + LogGroup "Test-PSModule" { + Get-GitHubZen + } 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/.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 diff --git a/README.md b/README.md index 3e74c20..b057339 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,47 @@ -# 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 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' | +| `Version` | The version of the GitHub module to install | false | 'latest' | +| `Prerelease` | Allow prerelease versions if available | false | 'false' | +| `WorkingDirectory` | The working directory where the script will run from | false | ${{ github.workspace }} | -### Outputs + + + + + + + ### Example ```yaml 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) diff --git a/action.yml b/action.yml index 2892a4a..c80c9dd 100644 --- a/action.yml +++ b/action.yml @@ -1,27 +1,60 @@ -name: '{{ NAME }}' -description: '{{ DESCRIPTION }}' -author: PSModule -branding: - icon: upload-cloud - color: white - -inputs: - working-directory: - description: The working directory where Terraform will be executed - required: false - subject: - description: The subject to greet - required: false - default: World - -runs: - using: composite - steps: - - name: '{{ NAME }}' - shell: pwsh - working-directory: ${{ inputs.working-directory }} - env: - GITHUB_ACTION_INPUT_subject: ${{ inputs.subject }} - run: | - # '{{ NAME }}' - . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" -Verbose +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 + color: white + +inputs: + Script: + description: The script to run. + required: true + Token: + description: The GitHub token to use. + required: false + default: ${{ github.token }} + Debug: + description: Enable debug output. + required: false + default: 'false' + Verbose: + description: Enable verbose output. + required: false + default: 'false' + Version: + description: | + Specifies the version of the resource to be returned. + The value can be an exact version or a version range using the NuGet versioning syntax. + required: false + Prerelease: + description: Allow prerelease versions if available. + required: false + default: 'false' + WorkingDirectory: + description: The working directory where the script will run from. + required: false + default: ${{ github.workspace }} + +runs: + using: composite + steps: + - name: Install GitHub + shell: pwsh + working-directory: ${{ inputs.WorkingDirectory }} + env: + GITHUB_TOKEN: ${{ inputs.Token }} + GITHUB_ACTION_INPUT_Debug: ${{ inputs.Debug }} + GITHUB_ACTION_INPUT_Verbose: ${{ inputs.Verbose }} + GITHUB_ACTION_INPUT_Version: ${{ inputs.Version }} + GITHUB_ACTION_INPUT_Prerelease: ${{ inputs.Prerelease }} + run: | + # GitHub-Script + if ($env:GITHUB_ACTION_INPUT_Debug -eq 'true') { + $DebugPreference = 'Continue' + } + if ($env:GITHUB_ACTION_INPUT_Verbose -eq 'true') { + $VerbosePreference = 'Continue' + } + . "$env:GITHUB_ACTION_PATH\scripts\main.ps1" + + ${{ inputs.Script }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b054fcc..c280e98 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,7 +1,14 @@ [CmdletBinding()] -param( - [Parameter()] - [string] $Subject = $env:GITHUB_ACTION_INPUT_subject -) +param() -Write-Host "Hello, $subject!" +$params = @{ + Name = 'GitHub' + Repository = 'PSGallery' + TrustRepository = $true + Prerelease = $env:GITHUB_ACTION_INPUT_Prerelease -eq 'true' +} +if (-not [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Version)) { + $params['Version'] = $env:GITHUB_ACTION_INPUT_Version +} +Install-PSResource @params +Import-Module -Name 'GitHub' -Force 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!"