Skip to content

Commit

Permalink
Declare licence. GitHub build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
rstarkov committed Dec 21, 2023
1 parent 326d05d commit 9673490
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build.yml
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
39 changes: 39 additions & 0 deletions .github/workflows/version.js
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,
};
};
1 change: 1 addition & 0 deletions Src/RT.ArithmeticCoding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Description>Implements an arithmetic coding encoder and decoder with support for adaptive symbol context.</Description>
<PackageTags>rt;arithmetic;entropy;coding</PackageTags>
<RepositoryUrl>https://github.com/RT-Projects/RT.ArithmeticCoding/</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

</Project>

0 comments on commit 9673490

Please sign in to comment.