diff --git a/.github/workflows/bump-flake-lock-and-selfup.yml b/.github/workflows/bump-flake-lock-and-selfup.yml index f68175a..da5b11c 100644 --- a/.github/workflows/bump-flake-lock-and-selfup.yml +++ b/.github/workflows/bump-flake-lock-and-selfup.yml @@ -12,12 +12,10 @@ on: jobs: bump: - uses: kachick/selfup/.github/workflows/reusable-bump-flake-lock-and-selfup.yml@action-v1 + uses: kachick/selfup/.github/workflows/reusable-bump-flake-lock-and-selfup.yml@v1.1.2 with: dry-run: ${{ github.event_name == 'pull_request' }} pr-title: 'Bump flake.lock and related dependencies' - optional-run: | - echo 'Add another changes and git commit here, especially for .node-version/.ruby-version' secrets: APP_ID: ${{ secrets.APP_ID }} APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} diff --git a/.github/workflows/ci-googleapi.yml b/.github/workflows/ci-googleapi.yml index 5d72e14..b2bee46 100644 --- a/.github/workflows/ci-googleapi.yml +++ b/.github/workflows/ci-googleapi.yml @@ -31,4 +31,4 @@ jobs: with: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' - - run: go test -tags=apitest ./... + - run: go test -count=1 -tags=apitest ./... diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index a0a8ea2..8fe4a33 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -17,4 +17,4 @@ jobs: with: # https://spdx.org/licenses/ allow-licenses: MIT, BSD-3-Clause, BSD-2-Clause, 0BSD, Unlicense, ISC, Apache-2.0, CC-BY-4.0 - allow-dependencies-licenses: pkg:githubactions/DeterminateSystems/nix-installer-action + allow-dependencies-licenses: pkg:githubactions/DeterminateSystems/nix-installer-action, pkg:githubactions/arduino/setup-task diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0ade55e..9a875c4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,14 +13,14 @@ jobs: - uses: actions/checkout@v4 - uses: dprint/check@v2.2 with: - dprint-version: '0.45.1' # selfup { "regex": "\\d[^']+", "script": "dprint --version | cut -d ' ' -f 2" } + dprint-version: '0.45.1' # selfup {"extract":"\\d[^']+","replacer":["dprint", "--version"], "nth": 2} typos: timeout-minutes: 15 runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: crate-ci/typos@v1.21.0 # selfup { "regex": "\\d\\.\\d+\\.\\d+", "script": "typos --version | cut -d ' ' -f 2" } + - uses: crate-ci/typos@v1.21.0 # selfup {"extract":"\\d\\.\\d+\\.\\d+","replacer":["typos", "--version"], "nth": 2} with: files: | . diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml new file mode 100644 index 0000000..a836d75 --- /dev/null +++ b/.github/workflows/snapshot.yml @@ -0,0 +1,64 @@ +name: 📸 + +on: + push: + branches: + - main + paths-ignore: + - '**.md' + pull_request: + paths-ignore: + - '**.md' + schedule: + # Every 10:42 JST + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule + - cron: '42 1 * * *' + workflow_dispatch: + +jobs: + bump_snapshot: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + # Needed to get commit counts + # https://stackoverflow.com/a/65056108 + fetch-depth: 0 + - name: Prepare Git user + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Prepare Git branch + id: prepare-branch + run: | + pr_branch="${{ github.sha }}-$(date +%Y%m%d-%H%M%S)" + git switch -c "${pr_branch}" + echo pr_branch="$pr_branch" | tee -a "$GITHUB_OUTPUT" + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + cache-dependency-path: 'go.sum' + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: '3.36.0' # selfup {"extract":"\\d\\.\\d+\\.\\d+","replacer":["task", "--version"], "nth": 3} + - run: | + task snapshot | tee -a snapshot.txt + - name: Update related CI dependencies + run: | + git diff-index --quiet HEAD || git commit -m 'Update snapshots' snapshot.txt + - name: Count added commits + id: count-commits + run: | + count="$(git rev-list --count origin/${{ github.event.repository.default_branch }}..)" + echo "count=${count}" | tee -a "$GITHUB_OUTPUT" + - name: Push branch + run: git push origin '${{ steps.prepare-branch.outputs.pr_branch }}' + if: github.event_name != 'pull_request' && (steps.count-commits.outputs.count > 0) + - name: Create PR + if: github.event_name != 'pull_request' && (steps.count-commits.outputs.count > 0) + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + gh pr create --base '${{ github.event.repository.default_branch }}' --title 'Update snapshots' --body 'Update snapshots' diff --git a/Taskfile.yml b/Taskfile.yml index 768bfab..a29fe74 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -21,7 +21,7 @@ tasks: - go test ./... test-all: cmds: - - go test -tags=apitest ./... + - go test -count=1 -tags=apitest ./... fmt: cmds: - dprint fmt @@ -31,6 +31,10 @@ tasks: - dprint check - typos . .github .vscode - nixpkgs-fmt --check ./*.nix + snapshot: + cmds: + - go run ./cmd/gwurl 'https://dl.google.com/tag/s/appguid%3D%7BDDCCD2A9-025E-4142-BCEB-F467B88CF830%7D%26iid%3D%7BBF6725E7-4A15-87B7-24D5-0ADABEC753EE%7D%26lang%3Dja%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520%25E6%2597%25A5%25E6%259C%25AC%25E8%25AA%259E%25E5%2585%25A5%25E5%258A%259B%26needsadmin%3Dtrue%26ap%3Dexternal-stable-universal/japanese-ime/GoogleJapaneseInputSetup.exe' | sort + - go run ./cmd/gwurl 'https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7B69ED4A6C-1B6F-4C8F-9298-FC4A61FC55C4%7D%26lang%3Dja%26browser%3D3%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-statsdef_1%26installdataindex%3Dempty/update2/installers/ChromeSetup.exe' | sort deps: cmds: - nix --version diff --git a/flake.nix b/flake.nix index baf1d0c..4048fff 100644 --- a/flake.nix +++ b/flake.nix @@ -45,7 +45,7 @@ # When updating go.mod or go.sum, update this sha together as following # vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # (`pkgs.lib.fakeSha256` returns invalid string in thesedays... :<) - vendorHash = "sha256-hC1eg2mC3Qp0QGFj3pTMIOyjrMV9Yx+hqvupxUG17OQ="; + vendorHash = "sha256-i07qu5jt4XTD2YxorJlAY/Kq1zk4yfiUSlSr3toBBGA="; }; packages.default = packages.gwurl; diff --git a/internal/googleapi/send_test.go b/internal/googleapi/send_test.go index 66ad857..edb7422 100644 --- a/internal/googleapi/send_test.go +++ b/internal/googleapi/send_test.go @@ -4,18 +4,16 @@ package googleapi import ( - "strings" + "regexp" + "slices" "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" ) func TestPostGoogleAPI(t *testing.T) { testCases := []struct { description string input App - want []string + want string ok bool }{ { @@ -24,15 +22,8 @@ func TestPostGoogleAPI(t *testing.T) { Appid: "{DDCCD2A9-025E-4142-BCEB-F467B88CF830}", Ap: "external-stable-universal", }, - want: []string{ - "http://edgedl.me.gvt1.com/edgedl/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi", - "https://edgedl.me.gvt1.com/edgedl/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi", - "http://dl.google.com/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi", - "https://dl.google.com/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi", - "http://www.google.com/dl/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi", - "https://www.google.com/dl/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi", - }, - ok: true, + want: "https?://[a-zA-Z0-9/.-]+_[0-9.]+/GoogleJapaneseInput[a-zA-Z0-9/.-]+\\.(exe|msi)", + ok: true, }, { description: "Google Chrome", @@ -40,29 +31,30 @@ func TestPostGoogleAPI(t *testing.T) { Appid: "{8A69D345-D564-463C-AFF1-A69D9E530F96}", Ap: "x64-stable-statsdef_1", }, - want: []string{ - "http://edgedl.me.gvt1.com/edgedl/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe", - "https://edgedl.me.gvt1.com/edgedl/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe", - "http://dl.google.com/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe", - "https://dl.google.com/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe", - "http://www.google.com/dl/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe", - "https://www.google.com/dl/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe", - }, - ok: true, + want: "https?://[a-zA-Z0-9/\\.-]+_[0-9\\.]+/[a-zA-Z0-9/\\.-]+_chrome_installer\\.(exe|msi)", + ok: true, }, { - description: "Unknown Prams", + description: "Unknown parameters", input: App{ Appid: "foo", Ap: "bar", }, - want: nil, - ok: false, + ok: false, }, } for _, tc := range testCases { t.Run(tc.description, func(t *testing.T) { + var wantPattern *regexp.Regexp + var err error + if tc.ok { + wantPattern, err = regexp.Compile(tc.want) + if err != nil { + t.Fatalf("unexpected error happened: %v", err) + } + } + resp, err := PostGoogleAPI(Os{ Platform: "win", Version: "10", @@ -88,13 +80,8 @@ func TestPostGoogleAPI(t *testing.T) { if !tc.ok { t.Fatalf("expected error did not happen") } - - dictComp := func(a string, b string) bool { - return strings.Compare(a, b) == -1 - } - - if diff := cmp.Diff(tc.want, urls, cmpopts.SortSlices(dictComp)); diff != "" { - t.Errorf("wrong result: %s", diff) + if slices.ContainsFunc(urls, func(u string) bool { return !wantPattern.MatchString(u) }) { + t.Errorf("returned urls contain unexpected pattern: %v", urls) } }) } diff --git a/snapshot.txt b/snapshot.txt new file mode 100644 index 0000000..e69de29