Skip to content

Commit

Permalink
Fix automatic releases (#395)
Browse files Browse the repository at this point in the history
Changes automatic release to not push release commits to any branch. Instead, the commit is simply tagged and only the tag is pushed. This results in the tags to not be included in any branch.
  • Loading branch information
rihi authored Mar 7, 2024
1 parent f65a3e2 commit 00c0dd2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with: # https://github.com/actions/checkout/issues/1471
fetch-depth: 0
fetch-tags: true

- name: Set git user
uses: fregante/setup-git-user@v2
Expand All @@ -25,15 +28,12 @@ jobs:
id: update
run: echo "version=$(python update_for_release.py)" >> "$GITHUB_OUTPUT" # returns new version to output

- name: Commit changes
- name: Commit changes & push
run: |
git add plugin.json
git commit -m "Update for release ${{ steps.update.outputs.version }}"
- name: Push changes and tags
run: |
git push origin HEAD
git push origin --tags
git tag "v${{ steps.update.outputs.version }}"
git push origin v${{ steps.update.outputs.version }}
- name: Create release
uses: softprops/action-gh-release@v1
Expand Down
1 change: 0 additions & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
],
"other": []
},
"version": "0.2.0",
"author": "fkie-cad",
"minimumbinaryninjaversion": 4271
}
21 changes: 14 additions & 7 deletions update_for_release.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import json
import subprocess
import time
from pathlib import Path

if __name__ == "__main__":
release_path = Path("plugin.json")
with release_path.open("r") as file:
data = json.load(file)

old_version: str = data["version"]
def get_patch(line: str) -> int:
return int(line[index + 1 :]) if (index := line.rfind(".")) != -1 else 0


if __name__ == "__main__":
new_version = time.strftime("%Y-%m-%d")

if old_version.startswith(new_version):
patch = int(old_version[index + 1 :]) if (index := old_version.rfind(".")) != -1 else 0
process = subprocess.run(["git", "tag", "-l", f"v{new_version}*"], text=True, capture_output=True)
patch = max((get_patch(line) for line in process.stdout.splitlines()), default=None)

if patch is not None:
new_version += f".{patch + 1}"

release_path = Path("plugin.json")
with release_path.open("r") as file:
data = json.load(file)

data["version"] = new_version

with release_path.open("w") as file:
Expand Down

0 comments on commit 00c0dd2

Please sign in to comment.