|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
| 5 | +env: |
| 6 | + SHA: ${{ GITHUB.SHA }} |
| 7 | + REF: ${{ GITHUB.REF }} |
| 8 | + RUN_ID: ${{ GITHUB.RUN_ID }} |
| 9 | + RUN_NUMBER: ${{ GITHUB.RUN_NUMBER }} |
| 10 | + BUILD_RUN_NUMBER: build.${{ GITHUB.RUN_NUMBER }} |
| 11 | + GITHUB_TOKEN: ${{ SECRETS.GITHUB_TOKEN }} |
| 12 | + MYGET_API_TOKEN: ${{ SECRETS.MYGET_API_KEY }} |
| 13 | + COVERALLS_REPO_TOKEN: ${{ SECRETS.COVERALLS_REPO_TOKEN }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: windows-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v3 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Install Chocolatey |
| 26 | + run: | |
| 27 | + Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) |
| 28 | + shell: powershell |
| 29 | + |
| 30 | + - name: Install Redis |
| 31 | + run: choco install redis-64 |
| 32 | + |
| 33 | + - name: Start Redis Server |
| 34 | + run: “C:\ProgramData\chocolatey\lib\redis-64\tools\redis-server.exe” |
| 35 | + |
| 36 | + - name: Setup .NET SDK |
| 37 | + uses: actions/setup-dotnet@v2 |
| 38 | + with: |
| 39 | + dotnet-version: | |
| 40 | + 3.1.x |
| 41 | + 5.0.x |
| 42 | + 6.0.x |
| 43 | + 7.0.x |
| 44 | + include-prerelease: true |
| 45 | + |
| 46 | + - name: Check .NET info |
| 47 | + run: dotnet --info |
| 48 | + |
| 49 | + - name: Install dependencies |
| 50 | + run: dotnet restore |
| 51 | + |
| 52 | + - name: Build solution |
| 53 | + run: dotnet build -c Release --no-restore |
| 54 | + |
| 55 | + - name: Test solution |
| 56 | + run: dotnet test -c Release --no-build --no-restore --verbosity normal --results-directory test-results --collect:"XPlat Code Coverage" ` |
| 57 | + -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=json,cobertura,lcov,teamcity,opencover |
| 58 | + |
| 59 | + - name: Upload coverage |
| 60 | + if: github.repository_owner == 'casbin-net' && github.event_name == 'push' |
| 61 | + run: | |
| 62 | + dotnet tool install coveralls.net --version 3.0.0 --tool-path tools; |
| 63 | + $CommitAuthor = git show -s --pretty=format:"%cn"; |
| 64 | + echo "Coomit author is: $CommitAuthor"; |
| 65 | + $CommitAuthorEmail = git show -s --pretty=format:"%ce"; |
| 66 | + echo "Coomit author email is: $CommitAuthorEmail"; |
| 67 | + $CommitMessage = git show -s --pretty=format:"%s"; |
| 68 | + echo "Coomit message is: $CommitMessage"; |
| 69 | + cp test-results/**/*.opencover.xml test-results |
| 70 | + tools/csmacnz.Coveralls --opencover -i test-results/coverage.opencover.xml --repoToken $env:COVERALLS_REPO_TOKEN ` |
| 71 | + --commitId $env:SHA --commitBranch $env:REF --commitAuthor "$CommitAuthor" ` |
| 72 | + --commitEmail "$CommitAuthorEmail" --commitMessage "$CommitMessage" ` |
| 73 | + --jobId $env:RUN_NUMBER --serviceName github-actions --useRelativePaths; |
| 74 | +
|
| 75 | + if($LastExitCode -ne 0) |
| 76 | + { |
| 77 | + Write-Warning -Message "Can not upload coverage, laat exit code is ${LastExitCode}." |
| 78 | + $LastExitCode = 0; |
| 79 | + } |
| 80 | +
|
| 81 | + - name: Upload test results artefacts |
| 82 | + if: github.repository_owner == 'casbin-net' && github.event_name == 'push' |
| 83 | + |
| 84 | + with: |
| 85 | + name: "drop-ci-test-results" |
| 86 | + path: './test-results' |
| 87 | + |
| 88 | + dry-run-semantic-release: |
| 89 | + runs-on: ubuntu-latest |
| 90 | + needs: build |
| 91 | + if: github.repository_owner == 'casbin-net' && github.event_name == 'push' |
| 92 | + |
| 93 | + steps: |
| 94 | + - name: Checkout |
| 95 | + uses: actions/checkout@v3 |
| 96 | + |
| 97 | + - name: Dry run semantic-release |
| 98 | + run: | |
| 99 | + export PATH=$PATH:$(yarn global bin) |
| 100 | + |
| 101 | + semantic-release --dry-run |
| 102 | +
|
| 103 | + release-build-version: |
| 104 | + runs-on: windows-latest |
| 105 | + needs: build |
| 106 | + if: github.repository_owner == 'casbin-net' && github.event_name == 'push' |
| 107 | + |
| 108 | + steps: |
| 109 | + - name: Checkout |
| 110 | + uses: actions/checkout@v3 |
| 111 | + with: |
| 112 | + fetch-depth: 0 |
| 113 | + |
| 114 | + - name: Git fetch tags |
| 115 | + run: git fetch --tags |
| 116 | + |
| 117 | + - name: Check tags |
| 118 | + run: git tag -l -n |
| 119 | + |
| 120 | + - name: Setup .NET SDK |
| 121 | + uses: actions/setup-dotnet@v2 |
| 122 | + with: |
| 123 | + dotnet-version: | |
| 124 | + 3.1.x |
| 125 | + 5.0.x |
| 126 | + 6.0.x |
| 127 | + 7.0.x |
| 128 | + include-prerelease: true |
| 129 | + |
| 130 | + - name: Check .NET info |
| 131 | + run: dotnet --info |
| 132 | + |
| 133 | + - name: Install dependencies |
| 134 | + run: dotnet restore |
| 135 | + |
| 136 | + - name: Build solution |
| 137 | + run: dotnet build -c Release --no-restore |
| 138 | + |
| 139 | + - name: Pack packages |
| 140 | + run: | |
| 141 | + $LastTag = git describe --tags (git rev-list --tags --max-count=1); |
| 142 | +
|
| 143 | + if [ -z "$LastTag" ]; then |
| 144 | + echo "Last tag is not available. Setting to a fixed string." |
| 145 | + LastTag="v2.0.0" |
| 146 | + fi |
| 147 | +
|
| 148 | + echo "Last tag is: $LastTag"; |
| 149 | + $Version = ($LastTag).TrimStart('v'); |
| 150 | + echo "Publishing version: $Version"; |
| 151 | + $NowBranchName = git rev-parse --abbrev-ref HEAD; |
| 152 | + echo "Now branch name: $NowBranchName"; |
| 153 | + $PackageVersion = ($LastTag).TrimStart('v') + "-" + $env:BUILD_RUN_NUMBER + "." + $NowBranchName + "." + $env:SHA.SubString(0, 7); |
| 154 | + echo "Publishing package version: ${PackageVersion}"; |
| 155 | + dotnet pack -c Release -o packages /p:PackageVersion=$PackageVersion /p:Version=$Version; |
| 156 | +
|
| 157 | + - name: Upload packages artefacts |
| 158 | + |
| 159 | + with: |
| 160 | + name: "drop-ci-build-packages" |
| 161 | + path: './packages' |
| 162 | + |
| 163 | + - name: Add myget nuget source |
| 164 | + run: dotnet nuget add source https://www.myget.org/F/casbin-net/api/v2/package --name myget.org |
| 165 | + |
| 166 | + - name: Push develop packages to myget.org |
| 167 | + run: dotnet nuget push .\packages\*.nupkg -s myget.org -k $env:MYGET_API_TOKEN --skip-duplicate |
0 commit comments