-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Declare licence. GitHub build script.
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Prepare version | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const script = require(require('path').resolve('./.github/workflows/version.js')) | ||
const vs = script({ context, github, firstRev: '45608175' }); | ||
const majmin = '1.2'; | ||
let ver_str = vs.formatVersion(`${majmin}.$(GitRevCount).$(RunNumber)-$(GitBranch) [$(GitSha6)/$(yyyy)-$(mm)-$(dd)]`); | ||
let ver_suf = vs.formatVersion('$(GitBranch)'); | ||
if (ver_suf == 'main') { | ||
ver_str = ver_str.replace('-main', ''); | ||
ver_suf = ''; | ||
} | ||
core.exportVariable('VER_STR', ver_str); | ||
core.exportVariable('VER_NUM', vs.formatVersion(`${majmin}.$(GitRevCount).$(RunNumber)`)); | ||
core.exportVariable('VER_SUF', ver_suf); | ||
- name: Install dotnet | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '8.x' | ||
dotnet-quality: 'ga' | ||
|
||
- name: dotnet restore | ||
run: dotnet restore | ||
|
||
- name: dotnet test | ||
run: dotnet test | ||
|
||
- name: "dotnet pack: ${{ env.VER_STR }}" | ||
run: dotnet pack Src/RT.ArithmeticCoding.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 | ||
|
||
- name: Push to NuGet | ||
run: dotnet nuget push Publish/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: RT.ArithmeticCoding-v${{env.VER_NUM}} | ||
path: Publish | ||
if-no-files-found: error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = ({ context, github, firstRev }) => { | ||
const { execSync } = require('child_process'); | ||
const fs = require('fs'); | ||
|
||
const d = new Date(); | ||
const verGitRevs = !firstRev ? '0' : execSync(`git rev-list ${firstRev}.. --count`).toString().trim(); | ||
|
||
function formatVersion(template) { | ||
template = template.replaceAll("$(yyyy)", (d.getYear() + 1900).toString()); | ||
template = template.replaceAll("$(yy)", (d.getYear() % 100).toString().padStart(2, '0')); | ||
template = template.replaceAll("$(mm)", (d.getMonth() + 1).toString().padStart(2, '0')); | ||
template = template.replaceAll("$(dd)", d.getDate().toString().padStart(2, '0')); | ||
template = template.replaceAll("$(GitRevCount)", verGitRevs); | ||
template = template.replaceAll("$(GitSha6)", String(process.env.GITHUB_SHA).substring(0, 6).toLowerCase()); | ||
template = template.replaceAll("$(GitSha8)", String(process.env.GITHUB_SHA).substring(0, 8).toLowerCase()); | ||
template = template.replaceAll("$(GitBranch)", context.ref.replace('refs/heads/', '')); | ||
template = template.replaceAll("$(RunNumber)", String(process.env.GITHUB_RUN_NUMBER)); | ||
return template; | ||
} | ||
|
||
function updateJson(filename, updateFunc) { | ||
var json = JSON.parse(fs.readFileSync(filename, 'utf8')); | ||
updateFunc(json); | ||
fs.writeFileSync(filename, JSON.stringify(json)); | ||
} | ||
function updateText(filename, find, replace) { | ||
let str = fs.readFileSync(filename, 'utf8'); | ||
if (str.indexOf(find) < 0) | ||
throw `Unable to find string "${find}" in file "${filename}"`; | ||
str = str.split(find).join(replace); | ||
fs.writeFileSync(filename, str); | ||
} | ||
|
||
return { | ||
formatVersion, | ||
updateJson, | ||
updateText, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters