Skip to content

Commit 56dec28

Browse files
author
Andrew Pearce
committed
Add GitHub Actions CI workflow and enhanced build script test coverage
Add GitHub Actions workflow for automated testing: - Build, unit, and security analysis on push/PR - PowerShell security scanning with PSScriptAnalyzer - Test result reporting and dependency review Streamline testing framework: - Simplify Invoke-Tests.ps1 parameter structure - Add CI mode with automatic cleanup - Improve error handling and diagnostics Update contributor documentation: - Complete fork-to-PR workflow in CONTRIBUTING.md - Testing guidance for new contributors Expand test coverage: - Build script validation and error scenarios - Module processing and template modification tests - Enhanced edge case testing This establishes automated quality gates while maintaining fast local development.
1 parent 8381424 commit 56dec28

7 files changed

Lines changed: 1016 additions & 810 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
#
6+
# https://github.com/microsoft/action-psscriptanalyzer
7+
# For more information on PSScriptAnalyzer in general, see
8+
# https://github.com/PowerShell/PSScriptAnalyzer
9+
10+
name: pwsh-runtime-unit-tests
11+
12+
on:
13+
push:
14+
branches: [main, "feature/**", "fix/**", "chore/**"]
15+
pull_request:
16+
branches: [main]
17+
types: [opened, synchronize, reopened]
18+
19+
permissions:
20+
contents: read
21+
checks: write
22+
pull-requests: write # Required for test reporter to comment on PRs
23+
actions: read # Required for test reporter to read workflow runs
24+
security-events: write # Required for SARIF upload to GitHub Security tab
25+
26+
jobs:
27+
pwsh-runtime-unit-tests:
28+
runs-on: ubuntu-latest
29+
timeout-minutes: 15
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
34+
with:
35+
fetch-depth: 1
36+
persist-credentials: false
37+
38+
- name: Dependency Review
39+
uses: actions/dependency-review-action@72eb03d02c7872a771aacd928f3123ac62ad6d3a # v4.3.3
40+
if: github.event_name == 'pull_request'
41+
42+
- name: Run Build Tests
43+
shell: pwsh
44+
run: |
45+
cd powershell-runtime
46+
pwsh -NoProfile -Command "& './tests/Invoke-Tests.ps1' -CI -TestType Build"
47+
48+
- name: Run Unit Tests
49+
shell: pwsh
50+
run: |
51+
cd powershell-runtime
52+
pwsh -NoProfile -Command "& './tests/Invoke-Tests.ps1' -CI -TestType Unit"
53+
54+
- name: Run PowerShell Security Analysis
55+
uses: microsoft/psscriptanalyzer-action@6b2948b1944407914a58661c49941824d149734f # v1.1
56+
with:
57+
path: ./powershell-runtime/source
58+
recurse: true
59+
output: psscriptanalyzer-results.sarif
60+
excludeRule: '"PSAvoidUsingWriteHost","PSUseSingularNouns"' # PSUseSingularNouns is temporary until a runtime function is renamed
61+
62+
- name: Upload PowerShell Analysis Results
63+
uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
64+
if: always()
65+
with:
66+
sarif_file: psscriptanalyzer-results.sarif
67+
category: powershell-analysis
68+
69+
- name: Upload Test Results
70+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
71+
if: always()
72+
with:
73+
name: test-results-${{ github.event.number || github.run_number }}
74+
path: |
75+
powershell-runtime/TestResults.xml
76+
powershell-runtime/CodeCoverage.xml
77+
psscriptanalyzer-results.sarif
78+
retention-days: 30

CONTRIBUTING.md

Lines changed: 132 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,163 @@ documentation, we greatly value feedback and contributions from our community.
66
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
77
information to effectively respond to your bug report or contribution.
88

9-
109
## Reporting Bugs/Feature Requests
1110

1211
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
1312

1413
When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
1514
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
1615

17-
* A reproducible test case or series of steps
18-
* The version of our code being used
19-
* Any modifications you've made relevant to the bug
20-
* Anything unusual about your environment or deployment
21-
16+
* A reproducible test case or series of steps
17+
* The version of our code being used
18+
* Any modifications you've made relevant to the bug
19+
* Anything unusual about your environment or deployment
2220

2321
## Contributing via Pull Requests
22+
2423
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
2524

26-
1. You are working against the latest source on the *main* branch.
27-
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28-
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
25+
1. You are working against the latest source on the *main* branch.
26+
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
27+
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
28+
29+
### Complete Contribution Workflow
30+
31+
#### Step 1: Fork and Setup
32+
33+
1. **Fork the repository** on GitHub
34+
2. **Clone your fork** locally:
35+
36+
```bash
37+
git clone https://github.com/YOUR-USERNAME/aws-lambda-powershell-runtime.git
38+
cd aws-lambda-powershell-runtime
39+
```
40+
41+
3. **Enable GitHub Actions** in your fork:
42+
* Go to the "Actions" tab in your fork
43+
* Click "I understand my workflows, go ahead and enable them"
44+
45+
#### Step 2: Create Your Branch
46+
47+
Use our standard branch naming conventions to enable automated testing:
48+
49+
```bash
50+
# For new features
51+
git checkout -b feature/your-feature-name
52+
53+
# For bug fixes
54+
git checkout -b fix/issue-description
55+
56+
# For maintenance tasks
57+
git checkout -b chore/maintenance-task
58+
```
59+
60+
#### Step 3: Make Your Changes
61+
62+
* Focus on the specific change you are contributing
63+
* Avoid reformatting unrelated code
64+
* Follow existing code style and conventions
65+
66+
#### Step 4: Test Your Changes
67+
68+
We provide two testing options:
69+
70+
##### Option A: Automated Testing in Your Fork (Recommended)
71+
72+
Push your changes to test automatically:
73+
74+
```bash
75+
git add .
76+
git commit -m "Add new feature with tests"
77+
git push origin feature/your-feature-name
78+
```
79+
80+
This triggers the same comprehensive test suite as the main repository:
81+
***Build Tests**: Validates PowerShell runtime builds correctly
82+
***Unit Tests**: Runs all tests with coverage reporting
83+
***Security Analysis**: PSScriptAnalyzer scans for issues
84+
***Dependency Review**: Checks for vulnerable dependencies
85+
86+
View results in your fork's Actions tab, fix any issues, and push again.
2987

30-
To send us a pull request, please:
88+
##### Option B: Local Testing
3189

32-
1. Fork the repository.
33-
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34-
3. Ensure local tests pass.
35-
4. Commit to your fork using clear commit messages.
36-
5. Send us a pull request, answering any default questions in the pull request interface.
37-
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
90+
Run tests locally before pushing:
3891

39-
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40-
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
92+
```bash
93+
cd powershell-runtime
4194

95+
# Run build tests
96+
pwsh -NoProfile -Command "& './tests/Invoke-Tests.ps1' -TestType Build"
97+
98+
# Run unit tests
99+
pwsh -NoProfile -Command "& './tests/Invoke-Tests.ps1' -TestType Unit"
100+
101+
# Run security analysis matching CI pipeline
102+
# (See .github/workflows/test.yml for exact configuration)
103+
Invoke-ScriptAnalyzer -Path ./source -Recurse -ExcludeRule 'PSAvoidUsingWriteHost','PSUseSingularNouns'
104+
```
105+
106+
#### Step 5: Submit Your Pull Request
107+
108+
1. **Ensure tests pass** in your fork
109+
2. **Create a pull request** from your branch to our main branch
110+
3. **Fill out the PR template** with details about your changes
111+
4. **Stay engaged** in the review process and address feedback
112+
113+
### Understanding Test Results
114+
115+
#### When Tests Pass ✅
116+
117+
```
118+
✅ Build Tests: All build tests passed
119+
✅ Unit Tests: 281+ tests passed, 87%+ coverage
120+
✅ Security Analysis: No critical issues found
121+
✅ Dependency Review: No vulnerable dependencies
122+
```
123+
124+
#### When Tests Fail ❌
125+
126+
```
127+
❌ Build Tests: 2 tests failed
128+
❌ Unit Tests: 5 tests failed, coverage below threshold
129+
⚠️ Security Analysis: 3 style issues found
130+
```
131+
132+
Click on failed workflow runs for detailed error messages, security annotations, and coverage reports.
133+
134+
### Troubleshooting
135+
136+
**Actions not running?**
137+
* Ensure Actions are enabled in your fork
138+
* Use proper branch naming (`feature/*`, `fix/*`, `chore/*`)
139+
* Don't push directly to `main` branch
140+
141+
**Tests fail in GitHub but pass locally?**
142+
* Check workflow logs for specific errors
143+
* Verify PowerShell version compatibility
144+
* Ensure all dependencies are properly specified
145+
146+
**Need help?**
147+
* Check existing issues for similar problems
148+
* Ask questions in GitHub issues with specific error messages
149+
* Reference workflow logs when requesting assistance
150+
151+
GitHub provides additional documentation on [forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
42152

43153
## Finding contributions to work on
44-
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.
45154

155+
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.
46156

47157
## Code of Conduct
158+
48159
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49160
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50-
opensource-codeofconduct@amazon.com with any additional questions or comments.
51-
161+
<opensource-codeofconduct@amazon.com> with any additional questions or comments.
52162

53163
## Security issue notifications
54-
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
55164

165+
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
56166

57167
## Licensing
58168

powershell-runtime/template.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
AWSTemplateFormatVersion: '2010-09-09'
1+
AWSTemplateFormatVersion: "2010-09-09"
22
Transform: AWS::Serverless-2016-10-31
33
Description: aws-lambda-powershell-runtime
44
##########################################################################
55
# Globals & Parameters #
66
##########################################################################
77
Resources:
8-
##########################################################################
9-
# Lambda layers #
10-
##########################################################################
8+
##########################################################################
9+
# Lambda layers #
10+
##########################################################################
1111
PwshRuntimeLayer:
1212
Type: AWS::Serverless::LayerVersion
1313
Properties:
@@ -34,4 +34,4 @@ Resources:
3434
Outputs:
3535
PwshRuntimeLayer:
3636
Value: !Ref PwshRuntimeLayer
37-
Description: PwshRuntimeLayer Layer ARN
37+
Description: PwshRuntimeLayer Layer ARN

0 commit comments

Comments
 (0)