Skip to content

Commit

Permalink
Update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
kzrnm committed Aug 5, 2024
1 parent ce56789 commit 630de33
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 37 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/publish-call.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test & Publish

on:
push:
branches:
- main
workflow_dispatch:
jobs:
publish:
uses: kzrnm/Kurukuru-PowerShell/.github/workflows/publish.yml@main
with:
module-name: git-completion
secrets: inherit

92 changes: 59 additions & 33 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,82 @@
name: Test & Publish

on:
push:
branches:
- master
workflow_dispatch:

workflow_call:
inputs:
module-name:
required: true
type: string
description: Module name
secrets:
powershell-gallery-token:
required: true
description: API Token of PowerShell Gallery
env:
Module: ${{ inputs.module-name }}
jobs:
get-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
is-new: ${{ steps.is-new-version.outputs.is-new }}
is-prerelease: ${{ steps.get-version.outputs.is-prerelease }}
new-tag: ${{ steps.is-new-version.outputs.new-tag }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Get Module Version
id: get-version
shell: pwsh
run: |
Import-Module ./kurukuru-pwsh.psd1
$version = (Get-Module kurukuru-pwsh).Version.ToString()
Write-Output $version
Write-Output "::set-output name=version::$version"
Import-Module "./src/${env:Module}.psd1"
$m = (Get-Module $env:Module)
$version = $m.Version.ToString()
$prerelease = $m.PrivateData.PSData.Prerelease
if ($prerelease) {
Write-Output "is-prerelease=true" | Tee-Object "$env:GITHUB_OUTPUT" -Append
$prerelease = "-$prerelease"
} else {
Write-Output "is-prerelease=false" | Tee-Object "$env:GITHUB_OUTPUT" -Append
}
Write-Output "version=$version$prerelease" | Tee-Object "$env:GITHUB_OUTPUT" -Append
- name: Check tag
uses: mukunku/tag-exists-action@v1.0.0
uses: mukunku/tag-exists-action@v1.6.0
id: check-tag
with:
tag: v${{ steps.get-version.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: is new version?
id: is-new-version
run: |
IS_NEW=false
TAG=""
if [ "${{ steps.check-tag.outputs.exists }}" = "false" ]; then
echo "new version tag project: ${{ steps.get-version.outputs.version }}"
IS_NEW=true
TAG="v${{ steps.get-version.outputs.version }}"
fi
echo "::set-output name=is-new::$IS_NEW"
echo "new-tag=$TAG" | tee -a "$GITHUB_OUTPUT"
test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
shell: [pwsh, powershell]
exclude:
- os: ubuntu-latest
shell: powershell
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run Pester
if: matrix.shell == 'pwsh'
shell: pwsh
run: Invoke-Pester ./tests/Start-Kurukuru.Tests.ps1
run: Invoke-Pester -CI
- name: Run Pester(Windows PowerShell)
if: matrix.shell == 'powershell'
shell: powershell
run: Invoke-Pester -CI

new-version-only:
runs-on: ubuntu-latest
needs: [get-version, test]
if: ${{ needs.get-version.outputs.is-new == 'true' }}
if: ${{ needs.get-version.outputs.new-tag != '' }}
steps:
- run: echo "new-version"

Expand All @@ -61,35 +86,36 @@ jobs:
name: actions
url: https://github.com
needs: [get-version, new-version-only]
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Push tag
id: tag-version
uses: mathieudutour/github-tag-action@v5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ needs.get-version.outputs.version }}
tag_prefix: "v"
run: |
tag="${{ needs.get-version.outputs.new-tag }}"
git tag "$tag"
git push origin "$tag"
- name: Create release
uses: ncipollo/release-action@v1
id: create-release
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.tag-version.outputs.new_tag }}
tag: ${{ needs.get-version.outputs.new-tag }}
name: Version ${{ needs.get-version.outputs.version }}
body: https://github.com/${{ github.repository }}/blob/${{ steps.tag-version.outputs.new_tag }}/CHANGELOG.md
body: ${{ github.server_url }}/${{ github.repository }}/blob/${{ steps.tag-version.outputs.new_tag }}/CHANGELOG.md
prerelease: ${{ needs.get-version.outputs.is-prerelease }}

- name: Install-Module PowerShellGet
shell: pwsh
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module PowerShellGet -MinimumVersion "3.0.12-beta" -AllowPrerelease -Repository PSGallery -AllowClobber -Force
Install-Module PowerShellGet -MinimumVersion " 3.0.23-beta23" -AllowPrerelease -Repository PSGallery -AllowClobber -Force
- name: Publish
shell: pwsh
run: |
$NUGET_KEY = "${{ secrets.PWSH_NUGET_KEY }}"
$NUGET_KEY = "${{ secrets.powershell-gallery-token }}"
tools/dist.ps1 -TagName "v${{ needs.get-version.outputs.version }}"
Import-Module PowerShellGet
Publish-PSResource -Path ./kurukuru-pwsh -APIKey "$NUGET_KEY" -Repository PSGallery
Publish-PSResource -Path "./$env:Module" -APIKey "$NUGET_KEY" -Repository PSGallery
4 changes: 2 additions & 2 deletions .github/workflows/update-kurukuru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Download Kurukuru
shell: pwsh
id: download-kurukuru
Expand All @@ -20,7 +20,7 @@ jobs:
run: cp tmp/New-Kurukuru.dll lib/Kurukuru.dll

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v6
with:
commit-message: Update Kurukuru.dll
delete-branch: true
Expand Down
2 changes: 1 addition & 1 deletion tests/Start-Kurukuru.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BeforeAll {
Import-Module "$PSScriptRoot/../kurukuru-pwsh.psd1"
$Pattern = [Kurukuru.Pattern]::new(
$script:Pattern = [Kurukuru.Pattern]::new(
@(
"0", "1", "2", "3", "4",
"5", "6", "7", "8", "9"
Expand Down
2 changes: 1 addition & 1 deletion tools/download_kurukuru.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ if ($downloadedAsmVersion.CompareTo($currentAsmVersion) -gt 0) {
Copy-Item $dllPath "$PSScriptRoot/../tmp/New-Kurukuru.dll"

Write-Output "Download new Kurukuru.dll $(Resolve-Path "$PSScriptRoot/../tmp/New-Kurukuru.dll")"
Write-Output "::set-output name=kurukuru-version::$downloadedAsmVersion"
Write-Output "kurukuru-version=$downloadedAsmVersion" >> $env:GITHUB_OUTPUT
}

0 comments on commit 630de33

Please sign in to comment.