Skip to content

Commit

Permalink
chore: fix release action bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdbalkhi committed Aug 9, 2022
1 parent c945bf3 commit 5f26f60
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 50 deletions.
54 changes: 34 additions & 20 deletions .github/workflows/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@
import sys
from datetime import datetime
from pathlib import Path
from platform import system
from subprocess import getoutput

from github import Github

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")

api_key = os.getenv("api_key", None)
current_date = datetime.today().strftime("%Y-%m-%d")
release_name = os.getenv("release_name", None)

if not (api_key and release_name):
logging.error(
"'api_key'/'release_name' not found in your envs."
f"please add this and run again, your envs are: {api_key} and {release_name}"
)
sys.exit(1)


# build
logging.info(msg="Building...")
if system() == "Windows":
os.system("make windows")
else:
os.system("make build")
logging.info(msg="Build complete")

try:
path = list(
Expand All @@ -22,28 +39,25 @@
logging.error("No built binary found")
sys.exit(1)

repo_name = os.getenv("name", None)
release_name = os.getenv("release_name", None)

if release_name is None:
release_name = getoutput("git describe --tags --always")

logging.info("Starting at %s", current_date)

if not (repo_name and api_key and release_name):
logging.error(
"'repo_name'/'api_key'/'release_name' not found in your envs."
"please add this and run again"
)
sys.exit(1)

if system().lower().startswith("nt"):
name = "windows"
elif system().lower().startswith("linux"):
name = "linux"
elif system().lower().startswith("darwin"):
name = "macos"
else:
name = system().lower()

path = (
Path(os.path.dirname(os.path.abspath(__file__)))
/ "../../"
/ path.rename(f"hascal-{name}-{release_name}")
)

gh = Github(api_key)
repo = gh.get_repo(f"hascal/{repo_name}")
repo = gh.get_repo("hascal/hascal")

release = repo.get_release(release_name)

logging.info("statrting Upload build file to release")

release.upload_asset(path=path)
release.upload_asset(path=str(os.path.normpath(path)))
logging.info("upload is done")
35 changes: 5 additions & 30 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
name: release
on:
workflow_dispatch:
inputs:
release_name:
description: "The name of the release e.g. v1.0.0"
required: true
release:
types:
- created
env:
api_key: ${{ secrets.GITHUB_TOKEN }}
release_name: ${{ github.event.inputs.release_name}} || ${{ github.event.release.name }}
release_name: ${{ github.event.release.name }}

jobs:
publish:
Expand All @@ -33,28 +28,8 @@ jobs:
- name: Update PIP ✨
if: ${{ matrix.os }} != windows-latest
run: python3 -m pip install -U wheel pip setuptools
- name: Install requirements ⚙️
- name: Install requirements
run: pip install -r requirements.txt PyGithub
- name: Build and Publish 📦
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
pip install -r requirements.txt pyGithub
else
pip3 install -r requirements.txt pyGithub
fi
- name: Build 🏗️
run: |
git checkout $release_name --quiet
if [ "${{ matrix.os }}" == "windows-latest" ]; then
make windows
else
make build
fi
- name: Publish 📦
run: |
# windows
if [ "${{ matrix.os }}" == "windows-latest" ]; then
mv dist\hascal dist\hascal-$Env:github.event.release.name-$Env:matrix.architecture-windows
python .github\workflows\publish.py
else
mv dist/hascal dist/hascal-${{ github.event.release.name }}-${{ matrix.architecture }}-${{ matrix.os }}
python3 .github/workflows/publish.py
fi
python3 .github/workflows/publish.py

0 comments on commit 5f26f60

Please sign in to comment.