From 31dcf8398b379edadc8a737dd15b7ab4251358e4 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Sun, 9 Aug 2020 07:31:44 +0000 Subject: [PATCH 01/14] Overwrite GITHUB_REF with a trigger input for testing purpose --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b5faed..a748a47 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,10 @@ name: Continuous Build on: workflow_dispatch: # Enable manual trigger + inputs: + refs: + description: Reference of git (like refs/heads/master or refs/tags/v1.0.0) + required: true push: branches: 'package/*' tags: '*' @@ -23,6 +27,10 @@ jobs: choco --version - name: Detect a target package # from a tag name or a branch name run: | + if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') { + # Overwrite GITHUB_REF with a trigger input + $env:GITHUB_REF = '${{ github.event.inputs.refs }}' + } $refs = $env:GITHUB_REF -split '/' if ($refs[1] -eq 'tags') { $packageId = $refs[2] From a3a4d298ac8628a00e2a65429edaad4d362c958a Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Sun, 9 Aug 2020 08:17:14 +0000 Subject: [PATCH 02/14] Change an input name from refs to git_ref --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a748a47..1ac06de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: Continuous Build on: workflow_dispatch: # Enable manual trigger inputs: - refs: + git_ref: description: Reference of git (like refs/heads/master or refs/tags/v1.0.0) required: true push: @@ -29,7 +29,7 @@ jobs: run: | if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') { # Overwrite GITHUB_REF with a trigger input - $env:GITHUB_REF = '${{ github.event.inputs.refs }}' + $env:GITHUB_REF = '${{ github.event.inputs.git_ref }}' } $refs = $env:GITHUB_REF -split '/' if ($refs[1] -eq 'tags') { From 9454a0e700c0fcd8a1e9d8a22cb6ad67557a27c6 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Sun, 9 Aug 2020 08:21:49 +0000 Subject: [PATCH 03/14] Make package and publish jobs to steps Because it's difficult to pass variables (like package id) among jobs. Steps is easier to pass variables among steps. --- .github/workflows/ci.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ac06de..eac3426 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,12 +41,7 @@ jobs: Write-Error -Message $message exit 1 } - 'Package:{0},Version:{1}' -f $env:PACKAGE_ID, $env:PACKAGE_VERSION - package: - runs-on: windows-2019 - steps: - - run: echo Packaging - publish: - runs-on: windows-2019 - steps: - - run: echo Publishing + - name: Package + run: Write-Host "Packaging $env:PACKAGE_ID" + - name: Publish + run: Write-Host "Publishing $env:PACKAGE_ID" From 36dfe18cacdb1ca046cf0093156c7fa18f1d0ef0 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Sun, 9 Aug 2020 08:22:27 +0000 Subject: [PATCH 04/14] Check existence of a package directory --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eac3426..a42707f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,13 @@ jobs: Write-Error -Message $message exit 1 } + if (-not (Test-Path -LiteralPath $packageId)) { + $message = 'Directory for package "{0}" not found' -f $packageId + Write-Error -Message $message + exit 1 + } + # Pass a package id to subsequent steps + "::set-env name=PACKAGE_ID::$packageId" - name: Package run: Write-Host "Packaging $env:PACKAGE_ID" - name: Publish From 367be113e311ffd9bbbc2cbebea21f13194e7621 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Sun, 9 Aug 2020 08:22:56 +0000 Subject: [PATCH 05/14] Misc. --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a42707f..a82ab9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ env: MSYS2_ROOT: 'C:\msys64' jobs: - init: + build: runs-on: windows-2019 steps: - uses: actions/checkout@v2 @@ -25,16 +25,21 @@ jobs: $PSVersionTable git --version choco --version + env | grep -i 'github\|runner' | sort + '${{ toJson(github) }}' - name: Detect a target package # from a tag name or a branch name run: | if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') { # Overwrite GITHUB_REF with a trigger input $env:GITHUB_REF = '${{ github.event.inputs.git_ref }}' } + ## Extract package id from ref $refs = $env:GITHUB_REF -split '/' if ($refs[1] -eq 'tags') { + # Tag like "refs/tags//" $packageId = $refs[2] - } else if (($refs[1] -eq 'heads') -and ($res[2] -eq 'package')) { + } elseif (($refs[1] -eq 'heads') -and ($refs[2] -eq 'package')) { + # Branch like "refs/heads/package/" $packageId = $refs[3] } else { $message = 'Cannot extract a package id from ref "{0}"' -f $env:GITHUB_REF From 6c4ac271a3e8ef00d64dad5237902a1b9a73c9c5 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Sun, 9 Aug 2020 08:27:22 +0000 Subject: [PATCH 06/14] Build a executable if needed --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a82ab9e..42726f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,14 @@ jobs: } # Pass a package id to subsequent steps "::set-env name=PACKAGE_ID::$packageId" + - name: Build (if build is required) + run: | + cd $env:PACKAGE_ID + if (Test-Path -LiteralPath build.bat) { + .\build.bat + } else { + 'Nothing to build' + } - name: Package run: Write-Host "Packaging $env:PACKAGE_ID" - name: Publish From c0ddfee21c0274139167f93cf707254759848bbc Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Mon, 10 Aug 2020 06:05:56 +0000 Subject: [PATCH 07/14] Fetch only 1 commit to reduce fetch time --- mozc-emacs-helper/build.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mozc-emacs-helper/build.bat b/mozc-emacs-helper/build.bat index fac2249..9c0d707 100644 --- a/mozc-emacs-helper/build.bat +++ b/mozc-emacs-helper/build.bat @@ -10,10 +10,10 @@ REM Install requirements choco install ninja --version 1.7.2 --yes REM Checkout source -"%GIT_COMMAND%" clone "%MOZC_REPOSITORY%" -b master --single-branch +"%GIT_COMMAND%" clone "%MOZC_REPOSITORY%" -b master --single-branch --depth 1 cd mozc "%GIT_COMMAND%" checkout "%COMMIT_HASH%" -"%GIT_COMMAND%" submodule update --init --recursive +"%GIT_COMMAND%" submodule update --init --recursive --depth 1 REM Build mozc "%PATCH_COMMAND%" -p1 < ..\win32_build.patch From 38c54bd893c3b702a7ee75c0edb7667de60e6e38 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Mon, 10 Aug 2020 06:08:39 +0000 Subject: [PATCH 08/14] Add env to point python 2.7 location Python 2.7 is required by mozc-emacs-helper. --- .github/workflows/ci.yml | 1 + mozc-emacs-helper/build.bat | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42726f9..bd54421 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ on: env: MINGW_ROOT: 'C:\MinGW' MSYS2_ROOT: 'C:\msys64' + PYTHON27_ROOT: 'C:\hostedtoolcache\windows\Python\2.7.18\x64' jobs: build: diff --git a/mozc-emacs-helper/build.bat b/mozc-emacs-helper/build.bat index 9c0d707..f196039 100644 --- a/mozc-emacs-helper/build.bat +++ b/mozc-emacs-helper/build.bat @@ -5,6 +5,8 @@ set PATCH_COMMAND=%MSYS2_ROOT%\usr\bin\patch set MOZC_REPOSITORY=https://github.com/google/mozc.git set COMMIT_HASH=afb03ddfe72dde4cf2409863a3bfea160f7a66d8 +REM Use python 2.7 +set PATH=%PYTHON27_ROOT%;%PATH% REM Install requirements choco install ninja --version 1.7.2 --yes From 075e23d59feaf188d40fcb90ca7d6c0332f3bbac Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Mon, 10 Aug 2020 06:14:01 +0000 Subject: [PATCH 09/14] Change MINGW_ROOT to fit mingw location on GitHub Action And configure PATH to it. --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd54421..03dec7d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: tags: '*' env: - MINGW_ROOT: 'C:\MinGW' + MINGW_ROOT: 'C:\msys64\mingw32' MSYS2_ROOT: 'C:\msys64' PYTHON27_ROOT: 'C:\hostedtoolcache\windows\Python\2.7.18\x64' @@ -56,8 +56,9 @@ jobs: "::set-env name=PACKAGE_ID::$packageId" - name: Build (if build is required) run: | - cd $env:PACKAGE_ID if (Test-Path -LiteralPath build.bat) { + # Add mingw toolchains into PATH + $env:PATH = "${env:MINGW_ROOT}/bin;${env:MSYS2_ROOT}/bin;${env:PATH}" .\build.bat } else { 'Nothing to build' From 1b11ba2e11899bfa0375c82a1ced0fb5e9bb1191 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Mon, 10 Aug 2020 06:14:23 +0000 Subject: [PATCH 10/14] Misc. --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03dec7d..6c37c5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: $PSVersionTable git --version choco --version - env | grep -i 'github\|runner' | sort + cmd /c "set" | grep -i 'github\|runner' | sort '${{ toJson(github) }}' - name: Detect a target package # from a tag name or a branch name run: | @@ -54,7 +54,8 @@ jobs: } # Pass a package id to subsequent steps "::set-env name=PACKAGE_ID::$packageId" - - name: Build (if build is required) + - name: Build (if needed) + working-directory: ${{ env.PACKAGE_ID }} run: | if (Test-Path -LiteralPath build.bat) { # Add mingw toolchains into PATH From 31fcbdda286c9e14cc9f7b09d94370bf6af76fe9 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Mon, 10 Aug 2020 06:15:56 +0000 Subject: [PATCH 11/14] Package a chocolatey package and test it if test.bat exists --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c37c5b..3f7d951 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,11 @@ jobs: 'Nothing to build' } - name: Package - run: Write-Host "Packaging $env:PACKAGE_ID" + working-directory: ${{ env.PACKAGE_ID }} + run: | + choco pack + if (Test-Path -LiteralPath test.bat) { + .\test.bat + } - name: Publish run: Write-Host "Publishing $env:PACKAGE_ID" From aff68978c218b1087e6defb302eb2fd8dc66238e Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Mon, 10 Aug 2020 06:16:59 +0000 Subject: [PATCH 12/14] Save a built nupkg as artifact --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f7d951..89e1d53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,5 +71,10 @@ jobs: if (Test-Path -LiteralPath test.bat) { .\test.bat } + - name: Save a package as artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ env.PACKAGE_ID }}_package + path: '**/*.nupkg' - name: Publish run: Write-Host "Publishing $env:PACKAGE_ID" From 03fbf9c8528a3d31ac53fa0c2fe7219038cc17c7 Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Mon, 10 Aug 2020 06:17:36 +0000 Subject: [PATCH 13/14] Publish a package to my myget feed --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89e1d53..800896f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,4 +77,5 @@ jobs: name: ${{ env.PACKAGE_ID }}_package path: '**/*.nupkg' - name: Publish - run: Write-Host "Publishing $env:PACKAGE_ID" + working-directory: ${{ env.PACKAGE_ID }} + run: choco push --source https://www.myget.org/F/kai2nenobu/ --api-key ${{ secrets.MYGET_API_KEY }} From 155f3202a296ee372fe27f7b1c9616ca9ba314ff Mon Sep 17 00:00:00 2001 From: Tsunenobu Kai Date: Mon, 10 Aug 2020 06:18:52 +0000 Subject: [PATCH 14/14] Change the workflow name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 800896f..a3f73f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Continuous Build +name: Continuous Packaging on: workflow_dispatch: # Enable manual trigger