diff --git a/.github/workflows/publish-call.yml b/.github/workflows/publish-call.yml new file mode 100644 index 0000000..2e48460 --- /dev/null +++ b/.github/workflows/publish-call.yml @@ -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 + \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3d40f56..4776766 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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" @@ -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 \ No newline at end of file diff --git a/.github/workflows/update-kurukuru.yml b/.github/workflows/update-kurukuru.yml index e7a747e..fe6e49b 100644 --- a/.github/workflows/update-kurukuru.yml +++ b/.github/workflows/update-kurukuru.yml @@ -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 @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json index 2a23085..a7047bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ "args": [ "-NoExit", "-Command", - "Import-Module ./kurukuru-pwsh.psd1" + "Import-Module ./src/kurukuru-pwsh.psd1" ], "overrideName": true }, @@ -18,7 +18,7 @@ "args": [ "-NoExit", "-Command", - "Import-Module ./kurukuru-pwsh.psd1" + "Import-Module ./src/kurukuru-pwsh.psd1" ], "overrideName": true }, diff --git a/kurukuru-pwsh.psd1 b/src/kurukuru-pwsh.psd1 similarity index 100% rename from kurukuru-pwsh.psd1 rename to src/kurukuru-pwsh.psd1 diff --git a/kurukuru-pwsh.psm1 b/src/kurukuru-pwsh.psm1 similarity index 100% rename from kurukuru-pwsh.psm1 rename to src/kurukuru-pwsh.psm1 diff --git a/tests/Start-Kurukuru.Tests.ps1 b/tests/Start-Kurukuru.Tests.ps1 index 8a80caf..5639ce4 100644 --- a/tests/Start-Kurukuru.Tests.ps1 +++ b/tests/Start-Kurukuru.Tests.ps1 @@ -1,6 +1,6 @@ BeforeAll { - Import-Module "$PSScriptRoot/../kurukuru-pwsh.psd1" - $Pattern = [Kurukuru.Pattern]::new( + Import-Module "$PSScriptRoot/../src/kurukuru-pwsh.psd1" + $script:Pattern = [Kurukuru.Pattern]::new( @( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" diff --git a/tools/dist.ps1 b/tools/dist.ps1 index 899097f..83b326d 100644 --- a/tools/dist.ps1 +++ b/tools/dist.ps1 @@ -7,9 +7,12 @@ param ( #Install-Module PowerShellGet -Scope CurrentUser -Force -AllowClobber $module = "kurukuru-pwsh" - +if (Test-Path "$module") { + Remove-Item -Recurse "$module/" +} mkdir $module -Copy-Item * -Recurse -Destination $module -Exclude $module, tools, .github, .gitignore, .vscode +Copy-Item * -Recurse -Destination $module -Exclude $module, tools, .github, .gitignore, .vscode, src +Copy-Item src/* -Recurse -Destination $module -Exclude $module, tools, .github, .gitignore, .vscode, src -(Get-Content "./$module.psd1" -Raw).Replace('blob/master', "blob/$TagName") | Out-File -Encoding utf8NoBOM -FilePath "./$module/$module.psd1" +(Get-Content "./src/$module.psd1" -Raw).Replace('blob/master', "blob/$TagName") | Out-File -Encoding utf8NoBOM -FilePath "./$module/$module.psd1" diff --git a/tools/download_kurukuru.ps1 b/tools/download_kurukuru.ps1 index 0c4880f..9c6e468 100644 --- a/tools/download_kurukuru.ps1 +++ b/tools/download_kurukuru.ps1 @@ -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 } \ No newline at end of file