Skip to content

Commit

Permalink
Add new way to resolve version
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski committed May 26, 2024
1 parent a43ccc3 commit ccc371d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
uses: ./
with:
debug: true
version-to-resolve: 'stable'

- uses: peter-evans/find-comment@v3
id: find_comment
Expand All @@ -29,6 +30,7 @@ jobs:
|_rc_|`${{ steps.agp-version-finder.outputs.latest-rc }}`|
|_beta_|`${{ steps.agp-version-finder.outputs.latest-beta }}`|
|_alpha_|`${{ steps.agp-version-finder.outputs.latest-alpha }}`|
|_resolved stable_|`${{ steps.agp-version-finder.outputs.resolved-version }}`|
edit-mode: replace
comment-id: ${{ steps.find_comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inputs:
description: 'if true, shows additional debug information'
required: false
default: 'false'
version-to-resolve:
description: 'Has to be one of `stable`, `alpha`, `beta`, `rc`. Will be translated into specific version, available under `outputs.resolved-version`'
required: false

outputs:
latest-alpha:
Expand All @@ -20,6 +23,9 @@ outputs:
latest-stable:
description: "Returns latest stable AGP version"
value: ${{ steps.run-action.outputs.latest-stable }}
resolved-version:
description: "Actual semver version resolved from `version-to-resolve`"
value: ${{ steps.run-action.outputs.resolved-version }}

branding:
color: 'green'
Expand All @@ -30,5 +36,6 @@ runs:
- id: run-action
env:
INPUT_DEBUG: ${{ inputs.debug }}
INPUT_VERSION_TO_RESOLVE: ${{ inputs.version-to-resolve }}
run: python3 '${{ github.action_path }}'/entrypoint.py
shell: bash
29 changes: 23 additions & 6 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def is_debug():


def github_output(key, value):
with open(os.environ['GITHUB_OUTPUT'], mode='a', encoding='UTF-8') as fh:
print(f'{key}={value}', file=fh)
print(f'{key}={value}')


url = "https://dl.google.com/android/maven2/com/android/tools/build/gradle/maven-metadata.xml"
Expand Down Expand Up @@ -44,7 +43,25 @@ def github_output(key, value):
rc_count={len(all_rc)}
""")

github_output(key="latest-stable", value=all_stable[-1])
github_output(key="latest-alpha", value=all_alpha[-1])
github_output(key="latest-beta", value=all_beta[-1])
github_output(key="latest-rc", value=all_rc[-1])
latest_stable = all_stable[-1]
latest_alpha = all_alpha[-1]
latest_beta = all_beta[-1]
latest_rc = all_rc[-1]

version_to_resolve = os.getenv("INPUT_VERSION_TO_RESOLVE", "")
if version_to_resolve == "stable":
resolved_version = latest_stable
elif version_to_resolve == "alpha":
resolved_version = latest_alpha
elif version_to_resolve == "beta":
resolved_version = latest_beta
elif version_to_resolve == "rc":
resolved_version = latest_rc
else:
resolved_version = ""

github_output(key="latest-stable", value=latest_stable)
github_output(key="latest-alpha", value=latest_alpha)
github_output(key="latest-beta", value=latest_beta)
github_output(key="latest-rc", value=latest_rc)
github_output(key="resolved-version", value=resolved_version)

0 comments on commit ccc371d

Please sign in to comment.