|
| 1 | + |
| 2 | +name: CI |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + release: |
| 7 | + types: published |
| 8 | + |
| 9 | +jobs: |
| 10 | + |
| 11 | + build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + #runs-on: ubuntu-16.04 |
| 14 | + steps: |
| 15 | + |
| 16 | + - name: checkout |
| 17 | + uses: actions/checkout@v1 |
| 18 | + |
| 19 | + - name: pester tests |
| 20 | + |
| 21 | + with: |
| 22 | + include_paths: ./tests/GitHubActions_tests.ps1 |
| 23 | + exclude_tags: SkipCI |
| 24 | + report_name: action_base_tests |
| 25 | + report_title: Action Base Tests |
| 26 | + gist_name: pwsh-github-action-base_tests.md |
| 27 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + gist_token: ${{ secrets.GIST_TOKEN }} |
| 29 | + gist_badge_label: Tests %ExecutedAt% |
| 30 | + |
| 31 | + # - name: pester tests manually |
| 32 | + # shell: pwsh |
| 33 | + # run: | |
| 34 | + # $neededModules = @( |
| 35 | + # 'Pester' |
| 36 | + # 'GitHubActions' |
| 37 | + # ) |
| 38 | + # $neededModules | % { |
| 39 | + # if (-not (Get-Module -ListAvailable $_)) { |
| 40 | + # Install-Module $_ -Force |
| 41 | + # } |
| 42 | + # } |
| 43 | + # ./tests/GitHubActions_tests.ps1 |
| 44 | + |
| 45 | + # - name: bundle distributable components |
| 46 | + # shell: pwsh |
| 47 | + # run: | |
| 48 | + # Compress-Archive -DestinationPath ./dist.zip -Path @( |
| 49 | + # 'js', 'lib' |
| 50 | + # 'SAMPLE-*', 'LICENSE', 'README.md' |
| 51 | + # ) |
| 52 | + |
| 53 | + - name: assemble distributable components |
| 54 | + shell: pwsh |
| 55 | + run: | |
| 56 | + mkdir ./dist |
| 57 | + Copy-Item ./_init ./dist/ -Recurse |
| 58 | + Copy-Item ./SAMPLE-* ./dist/ |
| 59 | + Copy-Item ./LICENSE ./dist/ |
| 60 | + Copy-Item ./README.md ./dist/ |
| 61 | +
|
| 62 | + - name: upload distributable artifact |
| 63 | + #if: startsWith(github.ref, 'refs/tags/v=') |
| 64 | + if: github.event_name == 'release' |
| 65 | + uses: actions/upload-artifact@v1 |
| 66 | + with: |
| 67 | + name: dist |
| 68 | + path: ./dist |
| 69 | + |
| 70 | + |
| 71 | + ## For testing out tests on Windows |
| 72 | + build-on-win: |
| 73 | + runs-on: windows-latest |
| 74 | + continue-on-error: true |
| 75 | + steps: |
| 76 | + |
| 77 | + - name: checkout |
| 78 | + uses: actions/checkout@v1 |
| 79 | + |
| 80 | + - name: pester tests |
| 81 | + |
| 82 | + with: |
| 83 | + include_paths: ./tests/GitHubActions_tests.ps1 |
| 84 | + exclude_tags: SkipCI |
| 85 | + report_name: action_base_tests-on-win |
| 86 | + report_title: Action Base Tests (On Windows) |
| 87 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + |
| 89 | + |
| 90 | + publish: |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: build |
| 93 | + if: github.event_name == 'release' |
| 94 | + steps: |
| 95 | + |
| 96 | + - name: download distributable artifact |
| 97 | + uses: actions/download-artifact@v1 |
| 98 | + with: |
| 99 | + name: dist |
| 100 | + |
| 101 | + - name: bundle distributable components |
| 102 | + shell: pwsh |
| 103 | + run: | |
| 104 | + cd dist |
| 105 | + Compress-Archive -DestinationPath ../pwsh-github-action-base-dist.zip -Path ./* |
| 106 | +
|
| 107 | + - name: attach asset to release |
| 108 | + shell: pwsh |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + run: | |
| 112 | + $tagName = $env:GITHUB_REF -replace 'refs/tags/','' |
| 113 | + $githubHeaders = @{ Authorization = "token $($env:GITHUB_TOKEN)" } |
| 114 | + $githubRepo = $env:GITHUB_REPOSITORY |
| 115 | + $listRelsUrl = "https://api.github.com/repos/$($githubRepo)/releases" |
| 116 | + $listRelsResp = Invoke-WebRequest -Headers $githubHeaders $listRelsUrl |
| 117 | + |
| 118 | + $listRels = $listRelsResp.Content | ConvertFrom-Json |
| 119 | + if (-not ($listRels.Count)) { |
| 120 | + throw "list releases response did not resolve to any releases" |
| 121 | + } |
| 122 | + else { |
| 123 | + Write-Output "Found [$($listRels.Count)] release(s)." |
| 124 | + } |
| 125 | +
|
| 126 | + $thisRel = $listRels | Where-Object { $_.tag_name -eq $tagName } |
| 127 | + if (-not $thisRel) { |
| 128 | + throw "could not find release for tag [$tagName]" |
| 129 | + } |
| 130 | + else { |
| 131 | + Write-Output "Found release [$($thisRel.tag_name)][$($thisRel.url)]" |
| 132 | + } |
| 133 | +
|
| 134 | + $uploadUrl = $thisRel.upload_url.Replace( |
| 135 | + '{?name,label}','?name=pwsh-github-action-base-dist.zip') |
| 136 | + $uploadHeaders = @{ |
| 137 | + "Authorization" = "token $($env:GITHUB_TOKEN)" |
| 138 | + "Content-Type" = "application/zip" |
| 139 | + } |
| 140 | + Write-Output "Adding asset to [$uploadUrl]" |
| 141 | + $uploadResp = Invoke-WebRequest -Headers $uploadHeaders $uploadUrl ` |
| 142 | + -InFile pwsh-github-action-base-dist.zip |
0 commit comments