From c8647ce1700a60bcfe7a1b671ca41968c0bc7139 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 24 Mar 2024 22:49:36 +0800 Subject: [PATCH 1/4] ci: add gha smoke test; drop outdated release script Signed-off-by: tison --- .github/workflows/ci.yml | 1 + Cargo.toml | 1 + release.py | 71 ---------------------------------------- 3 files changed, 2 insertions(+), 71 deletions(-) delete mode 100755 release.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd1517c..4aa7792 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,6 +97,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 + - uses: ./ - shell: bash run: | cargo run --bin hawkeye -- -V diff --git a/Cargo.toml b/Cargo.toml index 99d82e9..76b39bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,4 @@ tracing = "0.1.40" sign-tag = true shared-version = true tag-name = "v{{version}}" +pre-release-commit-message = "chore: release v{{version}}" diff --git a/release.py b/release.py deleted file mode 100755 index da6988e..0000000 --- a/release.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2024 tison -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, BooleanOptionalAction -import fileinput -from pathlib import Path -import re -import shutil -import subprocess -import tomllib - -parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) -parser.add_argument('version', help='version or level to bump') -parser.add_argument('--execute', '-x', action=BooleanOptionalAction, help='whether to execute the command (default to dry-run)') -args = parser.parse_args() - -basedir = Path(__file__).parent.absolute() - -# 0. Pull latest -subprocess.run(["git", "pull", "--rebase=true", "--autostash"], cwd=basedir, check=True) - -# 1. Bump version -if args.execute: - cmd = ["cargo", "release", "version", args.version, "-x"] -else: - cmd = ["cargo", "release", "version", args.version] - -subprocess.run(cmd, cwd=basedir, check=True) -info = tomllib.loads((basedir / 'Cargo.toml').read_text()) -version = info['workspace']['package']['version'] -version = f'v{version}' - -# 2. Update action.yml -pattern = re.compile(r'docker://ghcr.io/korandoru/hawkeye.*') -with fileinput.FileInput(basedir / 'action.yml', inplace=True, backup='.bak') as content: - for line in content: - print(pattern.sub(f'docker://ghcr.io/korandoru/hawkeye:{version}', line), end='') - -subprocess.run(["git", "--no-pager", "diff", "."], cwd=basedir, check=True) -if args.execute: - subprocess.run(["git", "add", "-A", "."], cwd=basedir, check=True) - subprocess.run(["git", "status"], cwd=basedir, check=True) - subprocess.run(["git", "commit", "-s", "-m", f"chore: release {version}"], cwd=basedir, check=True) - -# 3. Release -if args.execute: - cmd = ["cargo", "release", "-x"] -else: - cmd = ["cargo", "release"] -subprocess.run(cmd, cwd=basedir, check=args.execute) - -# 4. Change back action.yml -shutil.copy2(basedir / 'action.yml.bak', basedir / 'action.yml') -subprocess.run(["git", "--no-pager", "diff", "."], cwd=basedir, check=True) -if args.execute: - subprocess.run(["git", "add", "-A", "."], cwd=basedir, check=True) - subprocess.run(["git", "status"], cwd=basedir, check=True) - subprocess.run(["git", "commit", "-s", "-m", f"chore: post-release {version}"], cwd=basedir, check=True) - subprocess.run(["git", "push"], cwd=basedir, check=True) From be5251eaea72e1a0051a01a8b41552fbfa18c6c2 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 24 Mar 2024 23:01:31 +0800 Subject: [PATCH 2/4] try composite Signed-off-by: tison --- action.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index f64a0ac..bb60a58 100644 --- a/action.yml +++ b/action.yml @@ -32,9 +32,11 @@ inputs: default: check runs: - using: docker - image: Dockerfile - args: - - ${{ inputs.mode }} - - --config - - ${{ inputs.config }} + using: composite + steps: + - name: Build hawkeye binary + shell: bash + run: cd "$GITHUB_ACTION_PATH" && cargo install --path cli + - name: Execute command + shell: bash + run: hawkeye ${{ inputs.mode }} --config ${{ inputs.config }} From c0337f543bce5acc19eb7e8d9868dce65f7a9ce9 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 24 Mar 2024 23:05:43 +0800 Subject: [PATCH 3/4] print version for any possible debugging scenarios Signed-off-by: tison --- action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index bb60a58..173a0bc 100644 --- a/action.yml +++ b/action.yml @@ -39,4 +39,6 @@ runs: run: cd "$GITHUB_ACTION_PATH" && cargo install --path cli - name: Execute command shell: bash - run: hawkeye ${{ inputs.mode }} --config ${{ inputs.config }} + run: | + hawkeye -V + hawkeye ${{ inputs.mode }} --config ${{ inputs.config }} From dd7970dbf06782dc43e1bc53672ce00603d39a08 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 24 Mar 2024 23:33:16 +0800 Subject: [PATCH 4/4] rework Signed-off-by: tison --- .github/workflows/ci.yml | 10 +++++- Cargo.toml | 3 +- action.yml | 16 ++++----- release.py | 71 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 12 deletions(-) create mode 100755 release.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aa7792..c2874c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,11 +97,17 @@ jobs: steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 - - uses: ./ - shell: bash run: | cargo run --bin hawkeye -- -V cargo run --bin hawkeye -- check + gha: + # GitHub Actions with Docker is only supported on Linux runners now. + runs-on: ubuntu-latest + name: Smoke test for GitHub Actions + steps: + - uses: actions/checkout@v4 + - uses: ./ required: name: Required @@ -110,6 +116,7 @@ jobs: needs: - check - docker + - gha - smoke - test steps: @@ -118,6 +125,7 @@ jobs: if [[ ! ( \ "${{ needs.check.result }}" == "success" \ && "${{ needs.docker.result }}" == "success" \ + && "${{ needs.gha.result }}" == "success" \ && "${{ needs.smoke.result }}" == "success" \ && "${{ needs.test.result }}" == "success" \ ) ]]; then diff --git a/Cargo.toml b/Cargo.toml index 76b39bd..68ce9f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,4 +37,5 @@ tracing = "0.1.40" sign-tag = true shared-version = true tag-name = "v{{version}}" -pre-release-commit-message = "chore: release v{{version}}" +# Use release.py to replace content in action.yml now; so this commit is made ther. +#pre-release-commit-message = "chore: release v{{version}}" diff --git a/action.yml b/action.yml index 173a0bc..1a99178 100644 --- a/action.yml +++ b/action.yml @@ -32,13 +32,9 @@ inputs: default: check runs: - using: composite - steps: - - name: Build hawkeye binary - shell: bash - run: cd "$GITHUB_ACTION_PATH" && cargo install --path cli - - name: Execute command - shell: bash - run: | - hawkeye -V - hawkeye ${{ inputs.mode }} --config ${{ inputs.config }} + using: docker + image: docker://ghcr.io/korandoru/hawkeye:edge + args: + - ${{ inputs.mode }} + - --config + - ${{ inputs.config }} diff --git a/release.py b/release.py new file mode 100755 index 0000000..da6988e --- /dev/null +++ b/release.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# Copyright 2024 tison +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, BooleanOptionalAction +import fileinput +from pathlib import Path +import re +import shutil +import subprocess +import tomllib + +parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) +parser.add_argument('version', help='version or level to bump') +parser.add_argument('--execute', '-x', action=BooleanOptionalAction, help='whether to execute the command (default to dry-run)') +args = parser.parse_args() + +basedir = Path(__file__).parent.absolute() + +# 0. Pull latest +subprocess.run(["git", "pull", "--rebase=true", "--autostash"], cwd=basedir, check=True) + +# 1. Bump version +if args.execute: + cmd = ["cargo", "release", "version", args.version, "-x"] +else: + cmd = ["cargo", "release", "version", args.version] + +subprocess.run(cmd, cwd=basedir, check=True) +info = tomllib.loads((basedir / 'Cargo.toml').read_text()) +version = info['workspace']['package']['version'] +version = f'v{version}' + +# 2. Update action.yml +pattern = re.compile(r'docker://ghcr.io/korandoru/hawkeye.*') +with fileinput.FileInput(basedir / 'action.yml', inplace=True, backup='.bak') as content: + for line in content: + print(pattern.sub(f'docker://ghcr.io/korandoru/hawkeye:{version}', line), end='') + +subprocess.run(["git", "--no-pager", "diff", "."], cwd=basedir, check=True) +if args.execute: + subprocess.run(["git", "add", "-A", "."], cwd=basedir, check=True) + subprocess.run(["git", "status"], cwd=basedir, check=True) + subprocess.run(["git", "commit", "-s", "-m", f"chore: release {version}"], cwd=basedir, check=True) + +# 3. Release +if args.execute: + cmd = ["cargo", "release", "-x"] +else: + cmd = ["cargo", "release"] +subprocess.run(cmd, cwd=basedir, check=args.execute) + +# 4. Change back action.yml +shutil.copy2(basedir / 'action.yml.bak', basedir / 'action.yml') +subprocess.run(["git", "--no-pager", "diff", "."], cwd=basedir, check=True) +if args.execute: + subprocess.run(["git", "add", "-A", "."], cwd=basedir, check=True) + subprocess.run(["git", "status"], cwd=basedir, check=True) + subprocess.run(["git", "commit", "-s", "-m", f"chore: post-release {version}"], cwd=basedir, check=True) + subprocess.run(["git", "push"], cwd=basedir, check=True)