Skip to content

Commit

Permalink
Merge pull request #233 from chewing/ci-simplify-versioning
Browse files Browse the repository at this point in the history
ci: simplify version number scheme
  • Loading branch information
kanru authored Dec 22, 2024
2 parents dcd249b + c0389a6 commit 3609b1e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 46 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: CI

env:
VER_MAJOR: 24
VER_MINOR: 10
VER_PATCH: 0

on:
push:
branches: ["master"]
Expand Down Expand Up @@ -56,12 +61,20 @@ jobs:
vcpkg install --triplet x64-windows-static sqlite3
- name: Generate nightly version info
if: ${{ inputs.nightly }} || github.event_name == 'pull_request'
if: ${{ inputs.nightly }}
run: |
cargo xtask update-version -y 24 -m 10 -r 0 --nightly
cargo xtask update-version --major $env:VER_MAJOR --minor $env:VER_MINOR --patch $env:VER_PATCH -b $env:GITHUB_RUN_NUMBER
type version.rc
type installer/version.wxi
- name: Generate pull_request version info
if: github.event_name == 'pull_request'
env:
PR_NUMBER: ${{ github.event.number }}
run: |
cargo xtask update-version --major 0 --minor 0 --patch $env:PR_NUMBER -b $env:GITHUB_RUN_NUMBER
type version.rc
type installer/version.wxi
- name: Build
shell: cmd
Expand Down
35 changes: 26 additions & 9 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
name: Nightly Build

env:
VER_MAJOR: 24
VER_MINOR: 10
VER_PATCH: 0

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
# https://stackoverflow.com/questions/63014786/how-to-schedule-a-github-actions-nightly-build-but-run-it-only-when-there-where
check_date:
runs-on: ubuntu-latest
name: Check latest commit
outputs:
should_run: ${{ steps.should_run.outputs.should_run }}
steps:
- uses: actions/checkout@v2
- name: print latest_commit
run: echo ${{ github.sha }}

- id: should_run
continue-on-error: true
name: check latest commit is less than a day
if: ${{ github.event_name == 'schedule' }}
run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "::set-output name=should_run::false"

nightly-build:
needs: check_date
if: ${{ needs.check_date.outputs.should_run != 'false' }}
uses: ./.github/workflows/ci.yml
with:
nightly: true
Expand Down Expand Up @@ -35,16 +59,9 @@ jobs:
with:
tag_name: nightly
prerelease: true
name: 最新測試版 $$
name: 每日測試版 ${{env.VER_MAJOR}}.${{env.VER_MINOR}}.${{env.VER_PATCH}}.${{github.run_number}}
body: |
這是測試中的版本,可能較不穩定。若不確定,請使用正式釋出版。
最近更新:
```
TBD
```
**Full Changelog**: https://github.com/chewing/windows-chewing-tsf/compare/1ba881c...nightly
這是開發中的版本,可能較不穩定。若不確定,請使用最新的穩定版。
files: |
dist/windows-chewing-tsf.msi
dist/windows-chewing-tsf.msi.sha256
60 changes: 25 additions & 35 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::io::Write;

use jiff::{Timestamp, Zoned};
use jiff::Zoned;

mod flags {
xflags::xflags! {
Expand All @@ -11,14 +11,14 @@ mod flags {
cmd xtask {
/// Update the version.rc file.
cmd update-version {
/// The year of the release. (u32)
required -y, --year YY: u32
/// The month of the release. (u32)
required -m, --month MM: u32
/// The revision of the release. (u32)
required -r, --rev REV: u32
/// Generating release version, or nightly version.
optional --nightly
/// The major version of the release. (u32)
required --major MAJOR: u32
/// The minor version of the release. (u32)
required --minor MINOR: u32
/// The patch version of the release. (u32)
required --patch PATCH: u32
/// Optional build number (u32)
optional -b, --build BUILD_NUMBER: u32
}
}
}
Expand All @@ -37,10 +37,10 @@ mod flags {

#[derive(Debug)]
pub struct UpdateVersion {
pub year: u32,
pub month: u32,
pub rev: u32,
pub nightly: bool,
pub major: u32,
pub minor: u32,
pub patch: u32,
pub build: Option<u32>,
}

impl Xtask {
Expand Down Expand Up @@ -68,35 +68,25 @@ fn main() -> anyhow::Result<()> {
match flags.subcommand {
flags::XtaskCmd::UpdateVersion(update_version) => {
let now = Zoned::now();
let epoch: Timestamp = now.start_of_day()?.timestamp();
let year = now.year();
let month = now.month();
let day = now.day();
let day_of_year = now.day_of_year() as u32;
let sec = if update_version.nightly {
Timestamp::now().as_second() - epoch.as_second()
} else {
0
};
let yy = update_version.year;
let mm = update_version.month;
let rv = if update_version.nightly {
10_000 * update_version.rev + 9_000 + day_of_year
} else {
10_000 * update_version.rev + day_of_year
};
let yy = update_version.major;
let mm = update_version.minor;
let rv = update_version.patch;
let bn = update_version.build.unwrap_or_default();
let mut version_rc = File::create("version.rc")?;
indoc::writedoc!(
version_rc,
r#"
#define VER_FILEVERSION {yy},{mm},{rv},{sec}
#define VER_FILEVERSION_STR "{yy}.{mm}.{rv}.{sec}\0"
#define VER_PRODUCTVERSION {yy},{mm},{rv},{sec}
#define VER_PRODUCTVERSION_STR "{yy}.{mm}.{rv}.{sec}\0"
#define ABOUT_CAPTION_WITH_VER "關於新酷音輸入法 ({yy}.{mm}.{rv}.{sec})\0"
#define ABOUT_VERSION_STR "版本:24.{mm}.{rv}.{sec}\0"
#define VER_FILEVERSION {yy},{mm},{rv},{bn}
#define VER_FILEVERSION_STR "{yy}.{mm}.{rv}.{bn}\0"
#define VER_PRODUCTVERSION {yy},{mm},{rv},{bn}
#define VER_PRODUCTVERSION_STR "{yy}.{mm}.{rv}.{bn}\0"
#define ABOUT_CAPTION_WITH_VER "關於新酷音輸入法 ({yy}.{mm}.{rv}.{bn})\0"
#define ABOUT_VERSION_STR "版本:{yy}.{mm}.{rv}.{bn}\0"
#define ABOUT_RELEASE_DATE_STR "發行日期:{year} 年 {month:02} 月 {day:02} 日\0"
#define PREFS_TITLE_WITH_VER "設定新酷音輸入法 ({yy}.{mm}.{rv}.{sec})\0"
#define PREFS_TITLE_WITH_VER "設定新酷音輸入法 ({yy}.{mm}.{rv}.{bn})\0"
"#
)?;

Expand All @@ -106,7 +96,7 @@ fn main() -> anyhow::Result<()> {
r#"
<?xml version="1.0" encoding="UTF-8"?>
<Include>
<?define Version = "{yy}.{mm}.{rv}.{sec}"?>
<?define Version = "{yy}.{mm}.{rv}.{bn}"?>
</Include>
"#
)?;
Expand Down

0 comments on commit 3609b1e

Please sign in to comment.