Skip to content

Commit

Permalink
Merge pull request #58 from deploymenttheory/feat-test
Browse files Browse the repository at this point in the history
refactored release updater
  • Loading branch information
thejoeker12 authored Nov 8, 2024
2 parents e8039d6 + 15e29d2 commit 3282158
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json


def open_artifact(path: str, formatted_string: bool) -> dict:
def open_artifact(path: str, formatted_string: bool = False) -> dict:
"""
Opens and reads the outputs.json file created by a workflow and returns its contents as a dictionary.
Expand Down
32 changes: 19 additions & 13 deletions .github/scripts/update_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
- Valid GitHub authentication credentials
- outputs.json file containing status information
- Defined constants:
- REPO_PATH: Path to GitHub repository
- REPO: Path to GitHub repository
- GIT_TAG: Release tag to update
- DROPFILE_PATH: Location of outputs.json file
- ARTIFACT_PATH: Location of outputs.json file
Usage:
Run the script to fetch the specified release and append the
Expand All @@ -31,30 +31,36 @@
from github.GithubException import GithubException
from .shared import open_artifact

REPO_PATH = "deploymenttheory/terraform-demo-jamfpro-v2"
TOKEN = os.environ.get("GITHUB_TOKEN")
DROPFILE_PATH = os.environ.get("ARTIFACT_PATH")
REPO = os.environ.get("REPO")
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
ARTIFACT_PATH = os.environ.get("ARTIFACT_PATH")
GIT_TAG = os.environ.get("GIT_TAG")
ENV_VARS = [TOKEN, DROPFILE_PATH, GIT_TAG]

ENV_VARS = [
REPO,
GITHUB_TOKEN,
ARTIFACT_PATH,
GIT_TAG
]

if any (i == "" for i in ENV_VARS):
raise KeyError(f"one or more env vars are empty: {ENV_VARS}")


GH = github.Github(TOKEN)
GH = github.Github(GITHUB_TOKEN)


def get_update_release():
def get_and_update_release():
"""
Retrieves a GitHub release by tag and updates its description with apply status.
This function fetches a specific GitHub release using GIT_TAG, then appends the
status from outputs.json to the existing release description.
Dependencies:
- Requires GIT_TAG and REPO_PATH constants to be defined
- Requires GIT_TAG and REPO constants to be defined
- Requires GitHub authentication
- Requires outputs.json file with 'status' field at DROPFILE_PATH
- Requires outputs.json file with 'status' field at ARTIFACT_PATH
Raises:
GithubException: If the release cannot be found or updated
Expand All @@ -71,7 +77,7 @@ def get_update_release():
"""

try:
repo = GH.get_repo(REPO_PATH)
repo = GH.get_repo(REPO)
release = repo.get_release(GIT_TAG)

except GithubException as e:
Expand All @@ -81,7 +87,7 @@ def get_update_release():
print(f"Unexpected error: {e}")
raise

file = open_artifact(DROPFILE_PATH)
file = open_artifact(ARTIFACT_PATH)
message = f"{release.body}\nApply Result: {file["status"]}"
release.update_release(
name=release.tag_name,
Expand All @@ -90,7 +96,7 @@ def get_update_release():


def main():
get_update_release()
get_and_update_release()


if __name__ == "__main__":
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/update_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Add Realease Comment
on:
workflow_call:
inputs:
outputs-payload:
artifact-name:
required: true
type: string

Expand Down Expand Up @@ -33,12 +33,13 @@ jobs:
id: download-artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.outputs-payload }}
name: ${{ inputs.artifact-name }}

- name: Run pr update python utility
run: python .github/scripts/update_release.py
env:
ARTIFACT_PATH: ${{ steps.download-artifact.outputs.download-path }}
REPO: ${{ github.repository }}
ARTIFACT_PATH: ${{ steps.download-artifact.outputs.download-path }}/${{ vars.ARTIFACT_FN }}
GIT_TAG: ${{ inputs.git-tag }}


Expand Down

0 comments on commit 3282158

Please sign in to comment.