Skip to content

Commit

Permalink
feat: Add set-version functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
fundthmcalculus committed Nov 17, 2023
1 parent 3db68ae commit 1cde32a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
31 changes: 31 additions & 0 deletions actions/set-version/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Set Version'
description: 'Set environment variables based on latest version'
inputs:
githubToken:
description: 'the github token to use to fetch latest version'
required: true
default: ''
overrideVersion:
description: 'the version to force instead - overrides the latest version'
required: false
overrideRepository:
description: 'the repository whose latest version is desired'
required: false
default: ''
outputs:
packageVersion:
description: "the package version"
value: "${{ steps.fetchversion.outputs.packageVersion }}"
releaseVersion:
description: "the release name / version"
value: "${{ steps.fetchversion.outputs.releaseVersion }}"
runs:
using: "composite"
steps:
- id: fetchversion
run: |
${{ github.action_path }}/Set-Version.ps1 `
-Repo "${{ inputs.overrideRepository || github.repository }}" `
-GithubToken "${{ inputs.githubToken }}" `
-ManualVersion "${{ inputs.overrideVersion }}"
shell: pwsh
14 changes: 14 additions & 0 deletions actions/set-version/set-version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
param
(
[Parameter(Mandatory = $true)]
$Repo,
[Parameter(Mandatory = $true)]
$GithubToken,
$ManualVersion
)
$json = Invoke-WebRequest "https://api.github.com/repos/$Repo/releases/latest" `
-Headers @{ "Authorization" = "Token $GithubToken" } | ConvertFrom-Json
$version = if ([string]::IsNullOrEmpty($ManualVersion)) { $json.tag_name.Trim("v") } else { $ManualVersion.Trim("v") }

echo "releaseVersion=$($json.tag_name)" >> $env:GITHUB_OUTPUT
echo "packageVersion=$version" >> $env:GITHUB_OUTPUT

0 comments on commit 1cde32a

Please sign in to comment.