diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea9b896..91f4160 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,10 @@ name: CI +env: + VER_MAJOR: 24 + VER_MINOR: 10 + VER_PATCH: 0 + on: push: branches: ["master"] @@ -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 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index e11c40e..32e478e 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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 @@ -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 diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e25fd4e..c08a8de 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::io::Write; -use jiff::{Timestamp, Zoned}; +use jiff::Zoned; mod flags { xflags::xflags! { @@ -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 } } } @@ -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, } impl Xtask { @@ -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" "# )?; @@ -106,7 +96,7 @@ fn main() -> anyhow::Result<()> { r#" - + "# )?;