Skip to content

Commit 676e23b

Browse files
committed
Build script
1 parent 5d17538 commit 676e23b

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

.github/workflows/build.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: build
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
runs-on: windows-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Prepare version
18+
uses: actions/github-script@v6
19+
with:
20+
script: |
21+
const script = require(require('path').resolve('./.github/workflows/version.js'))
22+
const vs = script({ context, github, firstRev: '0eba8b1f' });
23+
let ver_str = vs.formatVersion('1.$(GitRevCount).$(RunNumber)-$(GitBranch) [$(GitSha6)/$(yyyy)-$(mm)-$(dd)]');
24+
let ver_suf = vs.formatVersion('$(GitBranch)');
25+
if (ver_suf == 'main') {
26+
ver_str = ver_str.replace('-main', '');
27+
ver_suf = '';
28+
}
29+
core.exportVariable('VER_STR', ver_str);
30+
core.exportVariable('VER_NUM', vs.formatVersion('1.$(GitRevCount).$(RunNumber)'));
31+
core.exportVariable('VER_SUF', ver_suf);
32+
33+
- name: Install dotnet
34+
uses: actions/setup-dotnet@v3
35+
with:
36+
dotnet-version: '8.x'
37+
dotnet-quality: 'ga'
38+
39+
- name: dotnet restore
40+
run: dotnet restore
41+
42+
- name: dotnet test
43+
run: dotnet test
44+
45+
- name: "dotnet pack: ${{ env.VER_STR }}"
46+
run: dotnet pack Src/RT.Keyboard.csproj --configuration Release -p:InformationalVersion="${{env.VER_STR}}" -p:VersionPrefix=${{env.VER_NUM}} -p:VersionSuffix=${{env.VER_SUF}} -p:FileVersion=${{env.VER_NUM}} -p:AssemblyVersion=${{env.VER_NUM}} -o Publish
47+
48+
- name: Push to NuGet
49+
run: dotnet nuget push Publish/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
50+
51+
- name: Upload artifact
52+
uses: actions/upload-artifact@v3
53+
with:
54+
name: RT.Keyboard-v${{env.VER_NUM}}
55+
path: Publish
56+
if-no-files-found: error

.github/workflows/version.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = ({ context, github, firstRev }) => {
2+
const { execSync } = require('child_process');
3+
const fs = require('fs');
4+
5+
const d = new Date();
6+
const verGitRevs = !firstRev ? '0' : execSync(`git rev-list ${firstRev}.. --count`).toString().trim();
7+
8+
function formatVersion(template) {
9+
template = template.replaceAll("$(yyyy)", (d.getYear() + 1900).toString());
10+
template = template.replaceAll("$(yy)", (d.getYear() % 100).toString().padStart(2, '0'));
11+
template = template.replaceAll("$(mm)", (d.getMonth() + 1).toString().padStart(2, '0'));
12+
template = template.replaceAll("$(dd)", d.getDate().toString().padStart(2, '0'));
13+
template = template.replaceAll("$(GitRevCount)", verGitRevs);
14+
template = template.replaceAll("$(GitSha6)", String(process.env.GITHUB_SHA).substring(0, 6).toLowerCase());
15+
template = template.replaceAll("$(GitSha8)", String(process.env.GITHUB_SHA).substring(0, 8).toLowerCase());
16+
template = template.replaceAll("$(GitBranch)", context.ref.replace('refs/heads/', ''));
17+
template = template.replaceAll("$(RunNumber)", String(process.env.GITHUB_RUN_NUMBER));
18+
return template;
19+
}
20+
21+
function updateJson(filename, updateFunc) {
22+
var json = JSON.parse(fs.readFileSync(filename, 'utf8'));
23+
updateFunc(json);
24+
fs.writeFileSync(filename, JSON.stringify(json));
25+
}
26+
function updateText(filename, find, replace) {
27+
let str = fs.readFileSync(filename, 'utf8');
28+
if (str.indexOf(find) < 0)
29+
throw `Unable to find string "${find}" in file "${filename}"`;
30+
str = str.split(find).join(replace);
31+
fs.writeFileSync(filename, str);
32+
}
33+
34+
return {
35+
formatVersion,
36+
updateJson,
37+
updateText,
38+
};
39+
};

Src/RT.Keyboard.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
88
<LangVersion>latest</LangVersion>
99

10-
<Version>1.0.0.9999</Version>
1110
<Authors>rstarkov;Timwi</Authors>
1211
<Description>GlobalKeyboardListener and other keyboard-related utilities.</Description>
1312
<PackageTags>rt.keyboard;GlobalKeyboardListener</PackageTags>

0 commit comments

Comments
 (0)