diff --git a/.github/workflows/pester.yml b/.github/workflows/pester.yml new file mode 100644 index 0000000..6a6fbba --- /dev/null +++ b/.github/workflows/pester.yml @@ -0,0 +1,84 @@ +name: "Run Pester tests" + +on: + push: + branches: + - donotexist + repository_dispatch: + types: + - webhook + +jobs: + job-main: + name: Build and Test + runs-on: ubuntu-latest + services: + shlink: + image: shlinkio/shlink:stable + ports: + - 80:8080 + env: + IS_HTTPS_ENABLED: false + DEFAULT_DOMAIN: psshlink.codaamok + options: --name shlink + steps: + - name: Modify DNS + run: echo "127.0.0.1 psshlink.codaamok" | sudo tee -a /etc/hosts + + - name: Checkout repository + uses: actions/checkout@v2.3.1 + with: + fetch-depth: 0 + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0.9.10 + with: + versionSpec: '5.x' + + - name: Determine Version + id: gitversion + uses: gittools/actions/gitversion/execute@v0.9.10 + with: + useConfigFile: true + + - name: Install codaamok.build and dependent modules, and set environment variables + run: | + Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted + Install-Module "InvokeBuild" -Force + $Username, $ProjectName = $env:GITHUB_REPOSITORY -split "/" + Invoke-Build -File "invoke.build.ps1" -ModuleName $ProjectName -Author $Username -Task "InstallDependencies","ImportBuildModule","SetGitHubActionEnvironmentVariables" + shell: pwsh + + - name: Build + run: | + $Params = @{ + ModuleName = $env:GH_PROJECTNAME + Author = $env:GH_USERNAME + Version = $env:GitVersion_MajorMinorPatch + NewRelease = $true + } + Invoke-Build -File "custom.build.ps1" @Params -Task PreBuild + Invoke-Build -File "invoke.build.ps1" @Params + Invoke-Build -File "custom.build.ps1" @Params -Task PostBuild + shell: pwsh + + - name: Generate Shlink API key + run: | + New-BuildEnvironmentVariable -Platform "GitHubActions" -Variable @{ + "ShlinkAPIKey" = [Regex]::Match((docker exec -t shlink shlink api-key:generate --no-ansi), '([0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12})') | + Select-Object -ExpandProperty Value | + ConvertTo-SecureString -AsPlainText -Force | + ConvertFrom-SecureString + "ShlinkServer" = "http://psshlink.codaamok" + } + shell: pwsh + + - name: Pester Acceptance Tests Report + uses: zyborg/pester-tests-report@v1.5.0 + with: + include_paths: './tests/Public/New-*.Acceptance.Tests.ps1, ./tests/Public/Get-*.Acceptance.Tests.ps1, ./tests/Public/Save-*.Acceptance.Tests.ps1, ./tests/Public/Set-ShlinkUrl.Acceptance.Tests.ps1, ./tests/Public/Set-ShlinkTag.Acceptance.Tests.ps1, ./tests/Public/Remove-*.Acceptance.Tests.ps1' + report_name: Pester Acceptance Tests Report + report_title: Pester Acceptance Tests Report + output_level: detailed + tests_fail_step: true + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/push.yml.old b/.github/workflows/push.yml.old deleted file mode 100644 index 529b54e..0000000 --- a/.github/workflows/push.yml.old +++ /dev/null @@ -1,91 +0,0 @@ -name: "Publish" - -on: - push: - branches: - - main - workflow_dispatch: - -jobs: - job-main: - name: main - runs-on: ubuntu-latest - if: "contains(github.event.head_commit.message, ':shipit:')" - steps: - - name: Checkout repository - uses: actions/checkout@v2.3.1 - - - name: Set environment variables - run: | - $Username, $ProjectName = $env:GITHUB_REPOSITORY -split "/" - Write-Output ("GH_PROJECTNAME={0}" -f $ProjectName) | Add-Content -Path $env:GITHUB_ENV - Write-Output ("GH_USERNAME={0}" -f $Username) | Add-Content -Path $env:GITHUB_ENV - shell: pwsh - - - name: Install dependent modules - run: | - $Modules = @( - "ChangelogManagement" - "InvokeBuild" - "PlatyPS" - ) - Install-Module -Name $Modules -Scope "CurrentUser" -Force -ErrorAction "Stop" - shell: pwsh - - - name: Build - run: | - $Modules = @( - "ChangelogManagement" - "InvokeBuild" - "PlatyPS" - ) - Import-Module -Name $Modules -ErrorAction "Stop" - Invoke-Build -ModuleName $env:GH_PROJECTNAME -Author $env:GH_USERNAME -NewRelease - shell: pwsh - - - name: Publish to PowerShell Gallery - run: Publish-Module -Path .\build\$env:GH_PROJECTNAME\ -NuGetApiKey $env:KEY -ErrorAction "Stop" -Force - shell: pwsh - env: - KEY: ${{ secrets.PSGALLERY_API_KEY }} - - - name: Create release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ env.VersionToBuild }} - release_name: Release ${{ env.VersionToBuild }} - body_path: release/releasenotes.txt - draft: false - prerelease: false - - - name: Upload release asset - id: upload_release_asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: release/${{ env.GH_PROJECTNAME }}_${{ env.VersionToBuild }}.zip - asset_name: ${{ env.GH_PROJECTNAME }}_${{ env.VersionToBuild }}.zip - asset_content_type: application/zip - - - name: Copy CHANGELOG.md and module manifest to repository root directory - run: | - Copy-Item -Path (".\build\{0}\CHANGELOG.md" -f $env:GH_PROJECTNAME) -Destination . -Force - Copy-Item -Path (".\build\{0}\{0}.psd1" -f $env:GH_PROJECTNAME) -Destination .\$env:GH_PROJECTNAME -Force - shell: pwsh - - - name: Commit CHANGELOG.md and module manifest - run: | - git config --global user.email "action@github.com" - git config --global user.name "GitHub Action" - git add CHANGELOG.md ${GH_PROJECTNAME}/${GH_PROJECTNAME}.psd1 docs - git commit -m "Released ${VersionToBuild}: updated change log and manifest" - - - name: Push commit - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e2f94bd --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: "Test workflow dispatch" + +on: + push: + branches: + - main + - master + workflow_dispatch: + +jobs: + job-main: + name: Test workflow dispatch + runs-on: ubuntu-latest + steps: + - name: Repository Dispatch + uses: peter-evans/repository-dispatch@v1.1.3 + with: + token: ${{ secrets.GH_PAT }} + repository: codaamok/PSShlink + event-type: webhook \ No newline at end of file