From 7f24f987e0dcc7ca64c6fbe647a846cf4b36f755 Mon Sep 17 00:00:00 2001 From: Mark Joshwel Date: Wed, 6 Sep 2023 22:28:14 +0000 Subject: [PATCH] ci(release),releaser: prepare for release --- .github/workflows/publish-slsa3-auto.yml | 18 +++++++++++++++--- .github/workflows/publish-slsa3-manual.yml | 15 ++++++++++++++- releaser.py | 21 +++++++++++++++------ 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish-slsa3-auto.yml b/.github/workflows/publish-slsa3-auto.yml index a63c920..d70617b 100644 --- a/.github/workflows/publish-slsa3-auto.yml +++ b/.github/workflows/publish-slsa3-auto.yml @@ -3,12 +3,11 @@ name: automated tagged release with slsa 3 compliance on: push: tags: - - '*' + - 'v*' jobs: build: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' permissions: contents: write outputs: @@ -17,15 +16,23 @@ jobs: steps: - name: checkout uses: actions/checkout@v3 + with: + ref: main + + - name: get branch name + id: get-branch-name + uses: tj-actions/branch-names@v7 - name: install devbox - uses: jetpack-io/devbox-install-action@v0.3.0 + uses: jetpack-io/devbox-install-action@v0.6.1 - name: install dependencies run: devbox run poetry install - name: run releaser.py run: devbox run python releaser.py + env: + SURPLUS_BUILD_BRANCH: ${{ steps.get-branch-name.outputs.base_ref_branch }} - name: build project id: build @@ -41,6 +48,11 @@ jobs: HASHES=$(sha256sum * | base64 -w0) echo "hashes=$HASHES" >> "$GITHUB_OUTPUT" + - uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist/ + - name: release uses: softprops/action-gh-release@v0.1.15 if: startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/publish-slsa3-manual.yml b/.github/workflows/publish-slsa3-manual.yml index 4d34c54..e662d7e 100644 --- a/.github/workflows/publish-slsa3-manual.yml +++ b/.github/workflows/publish-slsa3-manual.yml @@ -14,15 +14,23 @@ jobs: steps: - name: checkout uses: actions/checkout@v3 + with: + ref: main + + - name: get branch name + id: get-branch-name + uses: tj-actions/branch-names@v7 - name: install devbox - uses: jetpack-io/devbox-install-action@v0.3.0 + uses: jetpack-io/devbox-install-action@v0.6.1 - name: install dependencies run: devbox run poetry install - name: run releaser.py run: devbox run python releaser.py + env: + SURPLUS_BUILD_BRANCH: ${{ steps.get-branch-name.outputs.base_ref_branch }} - name: build project id: build @@ -45,6 +53,11 @@ jobs: files: | dist/*.whl + - uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist/ + provenance: needs: [build] permissions: diff --git a/releaser.py b/releaser.py index ed58520..c0e9edc 100644 --- a/releaser.py +++ b/releaser.py @@ -30,25 +30,34 @@ For more information, please refer to """ from datetime import datetime, timedelta, timezone +from os import getenv from pathlib import Path from subprocess import run + # NOTE: change this if surplus has moved path_surplus = Path(__file__).parent.joinpath("./surplus/surplus.py") build_time = datetime.now(timezone(timedelta(hours=8))) # using SGT -insert_build_branch: str = run( - "git rev-parse --abbrev-ref HEAD", - capture_output=True, - text=True, - shell=True, -).stdout.strip("\n") + +_insert_build_branch = getenv( + "SURPLUS_BUILD_BRANCH", + run( + "git branch --show-current", + capture_output=True, + text=True, + shell=True, + ).stdout.strip("\n"), +) +insert_build_branch = _insert_build_branch if _insert_build_branch != "" else "unknown" + insert_build_commit: str = run( "git rev-parse HEAD", capture_output=True, text=True, shell=True, ).stdout.strip("\n") + insert_build_datetime: str = repr(build_time).replace("datetime.", "") # NOTE: change this if the respective lines in surplus.py have changed