Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerCarrol authored Jul 22, 2024
0 parents commit 5592a56
Show file tree
Hide file tree
Showing 14 changed files with 953 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/actions/tools/annotation/error/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Error Annotation
description: Error Annotation

inputs:
message:
description: "Message to Display"
required: true

runs:
using: "composite"
steps:
- uses: actions/[email protected]
with:
script: |
var message = '${{ inputs.message }}';
message = message.replace(/(\r\n|\n|\r)/gm, '');
core.error(message);
17 changes: 17 additions & 0 deletions .github/actions/tools/annotation/notice/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Notice Annotation
description: Notice Annotation

inputs:
message:
description: "Message to Display"
required: true

runs:
using: "composite"
steps:
- uses: actions/[email protected]
with:
script: |
var message = '${{ inputs.message }}';
message = message.replace(/(\r\n|\n|\r)/gm, '');
core.notice(message);
17 changes: 17 additions & 0 deletions .github/actions/tools/annotation/warning/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Warning Annotation
description: Warning Annotation

inputs:
message:
description: "Message to Display"
required: true

runs:
using: "composite"
steps:
- uses: actions/[email protected]
with:
script: |
var message = '${{ inputs.message }}';
message = message.replace(/(\r\n|\n|\r)/gm, '');
core.warning(message);
47 changes: 47 additions & 0 deletions .github/actions/tools/exit-code/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Exit Code
description: Exit Code

inputs:
code:
description: "Exit Code Number (ensure it is unique across all workflows/actions)"
required: true
message:
description: "Exit Message"
required: false
default: ''
level:
description: "Annotation Level (Error, Warning, Debug, Notice)"
default: error

runs:
using: "composite"
steps:
- id: createMessage
uses: actions/[email protected]
with:
result-encoding: string
script: >
return '[Exit Code: ${{ inputs.code }}] ${{ inputs.message }} | Note: Search for "code: ${{ inputs.code }}" in the .github/ directory to find the source of this error'
- uses: ./.github/actions/tools/annotation/error
if: inputs.level == 'error'
with:
message: ${{ steps.createMessage.outputs.result }}

- uses: ./.github/actions/tools/annotation/warning
if: inputs.level == 'warning'
with:
message: ${{ steps.createMessage.outputs.result }}

- uses: ./.github/actions/tools/annotation/debug
if: inputs.level == 'debug'
with:
message: ${{ steps.createMessage.outputs.result }}

- uses: ./.github/actions/tools/annotation/notice
if: inputs.level == 'notice'
with:
message: ${{ steps.createMessage.outputs.result }}

- shell: cmd
run: exit ${{ inputs.code }}
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

updates:
- package-ecosystem: github-actions
directory: "/"
commit-message:
prefix: "(dependabot)"
reviewers:
- "${{ secrets.GHA_REVIEWER }}"
schedule:
interval: weekly

- package-ecosystem: nuget
directory: "/"
commit-message:
prefix: "(dependabot)"
reviewers:
- "${{ secrets.NUGET_REVIEWER }}"
schedule:
interval: weekly
56 changes: 56 additions & 0 deletions .github/ruleset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"id": 876151,
"name": "TJC NuGet Package Ruleset",
"target": "branch",
"source_type": "Repository",
"source": "TJC-Tools/TJC.Singleton",
"enforcement": "active",
"conditions": {
"ref_name": {
"exclude": [],
"include": [
"~DEFAULT_BRANCH"
]
}
},
"rules": [
{
"type": "deletion"
},
{
"type": "non_fast_forward"
},
{
"type": "pull_request",
"parameters": {
"required_approving_review_count": 1,
"dismiss_stale_reviews_on_push": true,
"require_code_owner_review": true,
"require_last_push_approval": true,
"required_review_thread_resolution": false
}
},
{
"type": "required_linear_history"
},
{
"type": "required_status_checks",
"parameters": {
"strict_required_status_checks_policy": true,
"required_status_checks": [
{
"context": "Continuous Testing (Testing.sln, 8.0.x)",
"integration_id": 15368
}
]
}
}
],
"bypass_actors": [
{
"actor_id": 1,
"actor_type": "OrganizationAdmin",
"bypass_mode": "pull_request"
}
]
}
124 changes: 124 additions & 0 deletions .github/workflows/ct-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Testing Matrix
run-name: PR#${{ github.event.number }}${{ github.event.pull_request.draft && ' [DRAFT]' || '' }} - Continuous Testing (Matrix) - (${{ github.event.pull_request.head.ref }}-to-${{ github.event.pull_request.base.ref }})

on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- ready_for_review

env:
build_directory: Build
test_project_suffix: Tests

concurrency:
group: Continuous-Testing-${{ github.event.pull_request.head.ref }}-to-${{ github.event.pull_request.base.ref }}
cancel-in-progress: true

jobs:
buildAndRunTests:
name: Continuous Testing
permissions: write-all
runs-on: windows-2022
if: ${{ !github.event.pull_request.draft }}
strategy:
fail-fast: false
matrix:
solution: [ Testing.sln ]
dotnet-version: [ '8.0.x' ]

steps:
- name: Checkout [${{ github.event.pull_request.head.ref }}]
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.TJC_TOKEN || secrets.GITHUB_TOKEN }}
submodules: recursive

####################################################################################################
### Initialize ###
####################################################################################################
# Check for Changes in the Non-Ignored Files; If there are none, then Skip Tests
# Skip: README, LICENSE, .gitignore, GitHub Workflows & Actions, etc.
- name: Check for Changes to Determine if Tests can be Skipped
id: getChanges
uses: tj-actions/[email protected]
with:
files_ignore: |
README.md
LICENSE
.github/**
.gitignore
- name: Check if Tests can be Skipped
id: getCanSkip
uses: actions/[email protected]
with:
result-encoding: string
script: |
var changes = '${{ fromJSON(steps.getChanges.outputs.any_modified) }}'
var skip = changes == 'false'
console.log('Skip:', skip)
return skip
####################################################################################################
### Prepare to Run Tests ###
####################################################################################################
- name: Setup .NET [${{ matrix.dotnet-version }}]
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}

- name: Setup NuGet
uses: NuGet/[email protected]

- name: Restore NuGet
run: nuget restore ${{ env.PROJECT_FILE_PATH }}

- name: Restore Dependencies
if: ${{ !fromJSON(steps.getCanSkip.outputs.result) }}
run: dotnet restore

####################################################################################################
### Run Tests ###
####################################################################################################
- name: Build
if: ${{ !fromJSON(steps.getCanSkip.outputs.result) }}
run: dotnet build --no-restore

- name: Error - Build Failed for ${{ matrix.solution }}
if: failure()
uses: ./.github/actions/tools/annotation/error
with:
message: '[Error] Build Failed for ${{ matrix.solution }}'

# Test 2 - Run All Unit Tests within Project
# Note: This Action Requires Windows
- name: Run Tests for [${{ matrix.solution }}]
if: ${{ !fromJSON(steps.getCanSkip.outputs.result) }}
run: dotnet test --no-build --verbosity normal

- name: Error - Tests Failed for ${{ matrix.solution }}
if: failure()
uses: ./.github/actions/tools/annotation/error
with:
message: '[Error] Tests Failed for ${{ matrix.solution }}'

####################################################################################################
### Notify Success ###
####################################################################################################
- name: Success - Successfully Built & Ran Tests for ${{ matrix.solution }}
if: success() && !fromJSON(steps.getCanSkip.outputs.result)
uses: ./.github/actions/tools/annotation/notice
with:
message: '[Success] Built & Ran Tests for ${{ matrix.solution }}'

- name: Success - Skipped Tests for ${{ matrix.solution }}
if: success() && fromJSON(steps.getCanSkip.outputs.result)
uses: ./.github/actions/tools/annotation/notice
with:
message: '[Success] Skipped Tests for ${{ matrix.solution }}'
80 changes: 80 additions & 0 deletions .github/workflows/push-creates-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Push -> Tag
run-name: Push [${{ github.ref_name }}] -> Tag

on:
push:
branches:
- main

concurrency:
group: Versioning-${{ github.ref_name }}
cancel-in-progress: false

env:
PROJECT_DIR_PATH: {REPLACE_ME_WITH_FOLDER_OF_CSPROJ} # E.g. TJC.LibraryName

jobs:
incrementPatch:
name: Push [${{ github.event.head_commit.message }}]
permissions: write-all
runs-on: windows-2022
outputs:
VersionNumber: ${{ steps.incrementVersion.outputs.result }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.TJC_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Check for Changes to See if Tagging can be Skipped
id: getChanges
uses: tj-actions/[email protected]
with:
files: ${{ env.PROJECT_DIR_PATH }}/**

- name: Get Last Version
id: getLastVersion
if: ${{ steps.getChanges.outputs.any_modified != 'false' }}
uses: actions/[email protected]
with:
result-encoding: string
script: |
try {
var latestTag = require("child_process").execSync("git describe --tags").toString().trim()
console.log('Latest Tag:', latestTag)
return latestTag
} catch {
return ""
}
- name: Get Next Version [${{ steps.getLastVersion.outputs.result }}]
id: getNextVersion
if: ${{ steps.getChanges.outputs.any_modified != 'false' }}
uses: actions/[email protected]
with:
result-encoding: string
script: |
var latestTag = "${{ steps.getLastVersion.outputs.result }}"
if (latestTag == "")
return "v0.1.0"
var ver = latestTag.replace("v","").split("-")[0]
console.log('Last Version:', "v" + ver)
var major = ver.split(".")[0]
var minor = ver.split(".")[1]
var patch = parseInt(ver.split(".")[2]) + 1
var next = "v" + major + "." + minor + "." + patch
console.log('Next Version:', next)
return next
- name: Tag Version [${{ steps.getNextVersion.outputs.result }}]
if: ${{ steps.getChanges.outputs.any_modified != 'false' }}
run: |
git tag ${{ steps.getNextVersion.outputs.result }}
git push origin tag ${{ steps.getNextVersion.outputs.result }}
- name: ${{ (steps.getChanges.outputs.any_modified == 'false') && 'Skipped Incrementing Version' || format('Incremented Version [{0}]', steps.getNextVersion.outputs.result) }}
if: success()
uses: ./.github/actions/tools/annotation/notice
with:
message: ${{ (steps.getChanges.outputs.any_modified == 'false') && 'Skipped Incrementing Version' || format('Incremented Version [{0}]', steps.getNextVersion.outputs.result) }}
Loading

0 comments on commit 5592a56

Please sign in to comment.