Skip to content

Commit 4ddca2b

Browse files
authored
feat: try using semantic-release to auto release (#5)
* feat: check build.yml Signed-off-by: Tan <[email protected]> * feat: Set redis service in ci Signed-off-by: Tan <[email protected]> * feat: fix a wrong path Signed-off-by: Tan <[email protected]> * feat: check release.yml Signed-off-by: Tan <[email protected]> * feat: fix dotnet version Signed-off-by: Tan <[email protected]> * fix: Fix missing .json and initial version numbers Signed-off-by: Tan <[email protected]> * fix: Chang the acquisition of two tokens Signed-off-by: Tan <[email protected]> --------- Signed-off-by: Tan <[email protected]>
1 parent 78fe658 commit 4ddca2b

File tree

4 files changed

+360
-0
lines changed

4 files changed

+360
-0
lines changed

.github/semantic.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Always validate the PR title AND all the commits
2+
titleAndCommits: true
3+
# Require at least one commit to be valid
4+
# this is only relevant when using commitsOnly: true or titleAndCommits: true,
5+
# which validate all commits by default
6+
anyCommit: true
7+
# Allow use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns")
8+
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
9+
allowMergeCommits: false
10+
# Allow use of Revert commits (eg on github: "Revert "feat: ride unicorns"")
11+
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
12+
allowRevertCommits: false

.github/workflows/build.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
uses: actions/[email protected]
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+
yarn global add [email protected]
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+
uses: actions/[email protected]
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

.github/workflows/release.yml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Release
2+
3+
on: push
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+
NUGET_API_TOKEN: ${{ SECRETS.NUGET_API_KEY }}
14+
COVERALLS_REPO_TOKEN: ${{ SECRETS.COVERALLS_REPO_TOKEN }}
15+
16+
jobs:
17+
build:
18+
runs-on: windows-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Install Chocolatey
27+
run: |
28+
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
29+
shell: powershell
30+
31+
- name: Install Redis
32+
run: choco install redis-64
33+
34+
- name: Start Redis Server
35+
run: “C:\ProgramData\chocolatey\lib\redis-64\tools\redis-server.exe”
36+
37+
- name: Setup .NET SDK
38+
uses: actions/setup-dotnet@v2
39+
with:
40+
dotnet-version: |
41+
3.1.x
42+
5.0.x
43+
6.0.x
44+
7.0.x
45+
include-prerelease: true
46+
47+
- name: Check .NET info
48+
run: dotnet --info
49+
50+
- name: Install dependencies
51+
run: dotnet restore
52+
53+
- name: Build solution
54+
run: dotnet build -c Release --no-restore
55+
56+
- name: Test solution
57+
run: dotnet test -c Release --no-build --no-restore --verbosity normal --results-directory test-results --collect:"XPlat Code Coverage" `
58+
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=json,cobertura,lcov,teamcity,opencover
59+
60+
- name: Upload coverage
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+
uses: actions/[email protected]
83+
with:
84+
name: "drop-ci-test-results"
85+
path: './test-results'
86+
87+
run-semantic-release:
88+
runs-on: ubuntu-latest
89+
needs: build
90+
if: github.repository_owner == 'casbin-net' && github.event_name == 'push'
91+
92+
steps:
93+
- name: Checkout
94+
uses: actions/checkout@v3
95+
96+
- name: Run semantic-release
97+
run: |
98+
export PATH=$PATH:$(yarn global bin)
99+
yarn global add [email protected]
100+
semantic-release
101+
102+
release:
103+
runs-on: windows-latest
104+
needs: run-semantic-release
105+
if: github.repository_owner == 'casbin-net' && github.event_name == 'push'
106+
107+
steps:
108+
- name: Checkout
109+
uses: actions/checkout@v3
110+
with:
111+
fetch-depth: 0
112+
113+
- name: Git fetch tags
114+
run: git fetch --tags
115+
116+
- name: Check tags
117+
run: git tag -l -n
118+
119+
- name: Setup .NET SDK
120+
uses: actions/setup-dotnet@v2
121+
with:
122+
dotnet-version: |
123+
3.1.x
124+
5.0.x
125+
6.0.x
126+
7.0.x
127+
include-prerelease: true
128+
129+
- name: Check .NET info
130+
run: dotnet --info
131+
132+
- name: Install dependencies
133+
run: dotnet restore
134+
135+
- name: Build solution
136+
run: dotnet build -c Release --no-restore
137+
138+
- name: Pack packages
139+
run: |
140+
$LastTag = git describe --tags (git rev-list --tags --max-count=1);
141+
echo "Last tag is: $LastTag";
142+
$Version = ($LastTag).TrimStart('v');
143+
echo "Publishing version: $Version";
144+
dotnet pack -c Release -o packages /p:PackageVersion=$Version /p:Version=$Version;
145+
146+
- name: Upload packages artefacts
147+
uses: actions/[email protected]
148+
with:
149+
name: "drop-ci-packages"
150+
path: './packages'
151+
152+
- name: Add myget nuget source
153+
run: dotnet nuget add source https://www.myget.org/F/casbin-net/api/v2/package --name myget.org
154+
155+
- name: Push packages to myget.org
156+
run: dotnet nuget push .\packages\*.nupkg -s myget.org -k $env:MYGET_API_TOKEN --skip-duplicate
157+
158+
- name: Add github nuget source
159+
run: dotnet nuget add source https://nuget.pkg.github.com/casbin-net/index.json --name github.com --username casbin-net --password $env:GITHUB_TOKEN
160+
161+
- name: Push packages to github.com
162+
run: dotnet nuget push .\packages\*.nupkg -s github.com --skip-duplicate;
163+
164+
- name: Push packages to nuget.org
165+
run: dotnet nuget push .\packages\*.nupkg -s nuget.org -k $env:NUGET_API_TOKEN --skip-duplicate

.releaserc.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"debug": true,
3+
"branches": [
4+
"+([0-9])?(.{+([0-9]),x}).x",
5+
"master",
6+
{
7+
"name": "preview",
8+
"prerelease": true
9+
}
10+
],
11+
"plugins": [
12+
"@semantic-release/commit-analyzer",
13+
"@semantic-release/release-notes-generator",
14+
"@semantic-release/github"
15+
]
16+
}

0 commit comments

Comments
 (0)