Skip to content

Commit f8a7d05

Browse files
Initial version
1 parent 748b99d commit f8a7d05

File tree

22 files changed

+792
-3
lines changed

22 files changed

+792
-3
lines changed

.gitattributes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Needed for publishing of examples, build worker defaults to core.autocrlf=input.
2+
* text eol=autocrlf
3+
4+
*.mof text eol=crlf
5+
*.sh text eol=lf
6+
*.svg eol=lf
7+
8+
# Ensure any exe files are treated as binary
9+
*.exe binary
10+
*.jpg binary
11+
*.xl* binary
12+
*.pfx binary
13+
*.png binary
14+
*.dll binary
15+
*.so binary

.github/linters/.markdown-lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
###########################
2+
## Markdown Linter rules ##
3+
###########################
4+
5+
# Linter rules doc:
6+
# - https://github.com/DavidAnson/markdownlint
7+
8+
###############
9+
# Rules by id #
10+
###############
11+
MD004: false # Unordered list style
12+
MD007:
13+
indent: 2 # Unordered list indentation
14+
MD013:
15+
line_length: 808 # Line length
16+
MD026:
17+
punctuation: ".,;:!。,;:" # List of not allowed
18+
MD029: false # Ordered list item prefix
19+
MD033: false # Allow inline HTML
20+
MD036: false # Emphasis used instead of a heading
21+
22+
#################
23+
# Rules by tags #
24+
#################
25+
blank_lines: false # Error on blank lines

.github/release.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes
2+
3+
changelog:
4+
categories:
5+
- title: Breaking Changes
6+
labels:
7+
- Major
8+
- Breaking
9+
- title: New Features
10+
labels:
11+
- Minor
12+
- Feature
13+
- Improvement
14+
- Enhancement
15+
- title: Other Changes
16+
labels:
17+
- '*'

.github/workflows/Action-Test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Action-Test
2+
3+
run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
4+
5+
on: [pull_request]
6+
7+
jobs:
8+
ActionTestSrc:
9+
strategy:
10+
matrix:
11+
path: [src, outputs/module]
12+
name: Action-Test - [${{ matrix.path }}]
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v4
17+
18+
- name: Initialize environment
19+
uses: PSModule/Initialize-PSModule@main
20+
21+
- name: Action-Test
22+
uses: ./
23+
env:
24+
GITHUB_TOKEN: ${{ github.token }}
25+
with:
26+
Name: PSModule
27+
Path: ${{ matrix.path }}

.github/workflows/Auto-Release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Auto-Release
2+
3+
run-name: "Auto-Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
4+
5+
on:
6+
pull_request_target:
7+
branches:
8+
- main
9+
types:
10+
- closed
11+
- opened
12+
- reopened
13+
- synchronize
14+
- labeled
15+
16+
concurrency:
17+
group: ${{ github.workflow }}
18+
19+
permissions:
20+
contents: write
21+
pull-requests: write
22+
23+
jobs:
24+
Auto-Release:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout Code
28+
uses: actions/checkout@v4
29+
30+
- name: Auto-Release
31+
uses: PSModule/Auto-Release@v1
32+
env:
33+
GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication
34+
with:
35+
IncrementalPrerelease: false

.github/workflows/Linter.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Linter
2+
3+
run-name: "Linter - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
4+
5+
on: [pull_request]
6+
7+
jobs:
8+
Lint:
9+
name: Lint code base
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repo
13+
uses: actions/checkout@v4
14+
15+
- name: Lint code base
16+
uses: github/super-linter@latest
17+
env:
18+
GITHUB_TOKEN: ${{ github.token }}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Ignore Visual Studio Code temporary files, build results, and
2+
## files generated by popular Visual Studio Code add-ons.
3+
##
4+
## Get latest from https://github.com/github/gitignore/blob/master/Global/VisualStudioCode.gitignore
5+
.vscode/*
6+
!.vscode/settings.json
7+
!.vscode/extensions.json
8+
*.code-workspace
9+
10+
# Local History for Visual Studio Code
11+
.history/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 PSModule
3+
Copyright (c) 2024 PSModule
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
1-
# test
2-
Action that is used to test PowerShell modules
1+
# Test-PSModule
2+
3+
Test PowerShell modules with Pester and PSScriptAnalyzer.
4+
5+
This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module.
6+
7+
## Specifications and practices
8+
9+
Test-PSModule follows:
10+
11+
- [Test-Driven Development](https://testdriven.io/test-driven-development/) using [Pester](https://pester.dev) and [PSScriptAnalyzer](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules)
12+
13+
## How it works
14+
15+
The action runs the following the Pester test framework:
16+
- [PSScriptAnalyzer tests](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/readme?view=ps-modules)
17+
- [PSModule framework tests](#psmodule-tests)
18+
- If `RunModuleTests` is set to `true`:
19+
- Custom module tests from the `tests` directory in the module repository.
20+
- Module manifest tests using [Test-ModuleManifest](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/test-modulemanifest)
21+
22+
The action fails if any of the tests fail or it fails to run the tests.
23+
24+
## How to use it
25+
26+
To use the action, create a new file in the `.github/workflows` directory of the module repository and add the following content.
27+
<details>
28+
<summary>Workflow suggestion - before module is built</summary>
29+
30+
```yaml
31+
name: Test-PSModule
32+
33+
on: [push]
34+
35+
jobs:
36+
Test-PSModule:
37+
name: Test-PSModule
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout repo
41+
uses: actions/checkout@v4
42+
43+
- name: Initialize environment
44+
uses: PSModule/Initialize-PSModule@main
45+
46+
- name: Test-PSModule
47+
uses: PSModule/Test-PSModule@main
48+
with:
49+
Name: PSModule # Needed if the repo is not named the same as the module
50+
Path: src
51+
RunModuleTests: false
52+
53+
```
54+
</details>
55+
56+
<details>
57+
<summary>Workflow suggestion - after module is built</summary>
58+
59+
```yaml
60+
name: Test-PSModule
61+
62+
on: [push]
63+
64+
jobs:
65+
Test-PSModule:
66+
name: Test-PSModule
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Checkout repo
70+
uses: actions/checkout@v4
71+
72+
- name: Initialize environment
73+
uses: PSModule/Initialize-PSModule@main
74+
75+
- name: Test-PSModule
76+
uses: PSModule/Test-PSModule@main
77+
with:
78+
Name: PSModule
79+
Path: outputs/modules
80+
81+
```
82+
</details>
83+
84+
## Usage
85+
86+
### Inputs
87+
88+
| Name | Description | Required | Default |
89+
| ---- | ----------- | -------- | ------- |
90+
| `Name` | The name of the module to test. The name of the repository is used if not specified. | `false` | |
91+
| `Path` | The path to the module to test. | `true` | |
92+
| `RunModuleTests` | Run the module tests. | `false` | `true` |
93+
94+
## PSModule tests
95+
96+
The [PSModule framework tests](https://github.com/PSModule/Test-PSModule/blob/main/scripts/tests/PSModule/PSModule.Tests.ps1) verifies the following coding practices that the framework enforces:
97+
98+
- Script filename and function/filter name should match.
99+
100+
## Tools
101+
102+
- Pester | [Docs](https://www.pester.dev) | [GitHub](https://github.com/Pester/Pester) | [PS Gallery](https://www.powershellgallery.com/packages/Pester/)
103+
- PSScriptAnalyzer [Docs](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules) | [GitHub](https://github.com/PowerShell/PSScriptAnalyzer) | [PS Gallery](https://www.powershellgallery.com/packages/PSScriptAnalyzer/)
104+
- PSResourceGet | [Docs](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.psresourceget/?view=powershellget-3.x) | [GitHub](https://github.com/PowerShell/PSResourceGet) | [PS Gallery](https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet/)
105+
- [Test-ModuleManifest | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/test-modulemanifest)
106+
- [PowerShellGet | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/PowerShellGet/test-scriptfileinfo)

action.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test-PSModule (by PSModule)
2+
description: Test a PowerShell module before publishing the module to the PowerShell Gallery.
3+
author: PSModule
4+
branding:
5+
icon: check-square
6+
color: gray-dark
7+
8+
inputs:
9+
Name:
10+
description: The name of the module to test. The name of the repository is used if not specified.
11+
required: false
12+
Path:
13+
description: The path to the module to test.
14+
required: true
15+
RunModuleTests:
16+
description: Run the module tests.
17+
required: false
18+
default: 'true'
19+
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Run Test-PSModule
24+
shell: pwsh
25+
env:
26+
GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }}
27+
GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }}
28+
GITHUB_ACTION_INPUT_RunModuleTests: ${{ inputs.RunModuleTests }}
29+
run: |
30+
# Test-PSModule
31+
. "$env:GITHUB_ACTION_PATH\scripts\main.ps1" -Verbose

0 commit comments

Comments
 (0)