Skip to content

Commit

Permalink
rework
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Mar 24, 2024
1 parent c0337f5 commit dd7970d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 12 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -110,6 +116,7 @@ jobs:
needs:
- check
- docker
- gha
- smoke
- test
steps:
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
16 changes: 6 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
71 changes: 71 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
# Copyright 2024 tison <[email protected]>
#
# 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)

0 comments on commit dd7970d

Please sign in to comment.