Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpatton1971 committed Jan 18, 2024
1 parent 9a16f69 commit ede3f51
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/create-releasenotes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Milestone Closure Trigger

on:
milestone:
types: [closed]

jobs:
create-release-notes:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

# Your additional steps go here. For example:
- name: Create Release Notes
uses: mod-posh/[email protected]
with:
milestone_number: ${{ github.event.milestone.number }}
verbose: 'verbose'
github_token: ${{ secrets.GITHUB_TOKEN }}
62 changes: 62 additions & 0 deletions .github/workflows/csharp-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: C-Sharp Project Workflow
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

workflow_dispatch:

jobs:
Build:
name: Build, Test and Package
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Install DefaultDocumentation
run: dotnet tool install DefaultDocumentation.Console -g
- name: Clean Project
run: |
$projectPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'CSharpProject'
$outputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Output'
$docsPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Docs'
dotnet clean $projectPath --nologo -c Debug
dotnet clean $projectPath --nologo -c Release
$null = Remove-Item $outputPath -Recurse -ErrorAction Ignore
$null = New-Item -Type Directory -Path $outputPath -ErrorAction Ignore
$null = New-Item -Type Directory -Path $docsPath -ErrorAction Ignore
- name: Test Project
run: |
$projectPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'CSharpProject.Tests'
dotnet test $projectPath --nologo
- name: Build Project
run: |
$projectPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'CSharpProject'
$outputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Output'
dotnet build $projectPath -o $outputPath
Get-ChildItem -Path $outputPath
- name: Create Documentation
run: |
$outputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Output'
$docsPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Docs'
defaultdocumentation -a $outputPath\CSharpProject.dll -o $docsPath
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "Document updates"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release
uses: mod-posh/[email protected]
with:
name: '"Our latest awesome release"'
version: '"2.0.4"'
verbose: "verbose"
body: '"This release adds some features."'
github_token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
All changes to this project should be reflected in this document.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

---

## [[0.0.1.0]](https://github.com/mod-posh/GetProjectVersion/releases/tag/v0.0.1.0) - 2024-01-18

This is the initial release of this action. It can be used to pass the project version to another action in your workflow.

---
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# modposh-template
# Get Project Version GitHub Action

## Overview

The GetProjectVersion Action returns the current version of your project based on the version of a given project file. There are currently only two file types supported:

1. .csproj - C-Sharp project files
2. .psd1 - PowerShell Module Manifest files

## Workflow File

You can trigger the `action.yml` by `workflow_call` to post a notification automatically. The workflow contains several steps to act:

1. Checkout the repository
2. Call the `getprojectversion.ps1` script

### Workflow Inputs

- `Filename`: If the file is in the root of the repository, it's just the filename, project.csproj. If the file is inside a folder, it's the relative path to that file, MyProject\project.psd1
- `verbose`: A value of verbose will output additional information

## PowerShell Script (`getprojectversion.ps1`)

The PowerShell script opens the given project file and returns the string value of the version.

## Usage

There are a few different ways you could use this action; here is an example of one way to get you started.

```yaml
jobs:
GetVersion:
uses: mod-posh/[email protected]
with:
Filename: '"MyModule.psd1"'
verbose: 'verbose'
```
> [!Note]
> This example is used directly as part of a larger workflow
> The verbose option will output a little more detail in the logs
## License
This project is licensed using the [Gnu GPL-3](LICENSE).
35 changes: 35 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'GetProjectVersion'
description: 'Get the current version of your project'
author: 'Jeff Patton'

branding:
icon: 'bell'
color: 'blue'

inputs:
Filename:
description: 'The filename of the project or relative path to the project file'
required: true
type: string
verbose:
description: "A value of verbose will output additional information"
required: false
type: string
default: 'None'

runs:
using: 'composite'
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Get Project Version
env:
VERBOSE: ${{ inputs.verbose }}
run: |
$Version = & $env:GITHUB_ACTION_PATH\\getprojectversion.ps1 -Filename ${{ inputs.Filename }}
echo "::set-output name=Version::$Version"
shell: pwsh
id: GetProjectVersion
outputs:
version: ${{ steps.GetProjectVersion.outputs.Version }}
46 changes: 46 additions & 0 deletions getprojectversion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
param (
[string]$Filename
)
try {
$ErrorActionPreference = 'Stop';
$Error.Clear();
$sourcePath = $env:GITHUB_WORKSPACE


if ($verbose.ToLower() -eq 'verbose')
{
Write-Host "GetProjectVersion DEBUG"
Write-Host "Filename : $($Filename)"
Write-Host "SourcePath : $($sourcePath)"
}

$File = Get-Item -Path (Join-Path -Path $sourcePath -ChildPath $FileName)
switch ($File.Extension)
{
'.csproj'
{
$Project = [xml](Get-Content -Path $File.FullName);
$Version = $Project.Project.PropertyGroup.Version.ToString();
}
'.psd1'
{
$Manifest = Test-ModuleManifest -Path $File.FullName -ErrorAction SilentlyContinue
$Version = $Manifest.Version.ToString()
}
default
{
throw "The extension, $($File.Extension) is not currently a supported type, please create an issue to address this"
}
}

if ($verbose.ToLower() -eq 'verbose')
{
Write-Host "Extension : $($File.Extension)"
Write-Host "Version : $($Version)"
}

return $Version
} catch {
$_.InvocationInfo | Out-String;
throw $_.Exception.Message;
}

0 comments on commit ede3f51

Please sign in to comment.