-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
87 lines (81 loc) · 3.12 KB
/
action.yml
File metadata and controls
87 lines (81 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# SPDX-FileCopyrightText: 2025 Joe Pitt
#
# SPDX-License-Identifier: GPL-3.0-only
---
name: Get Latest Version from GitHub Package
author: Joe Pitt
description: Get the latest version from a GitHub package.
inputs:
token:
description: The token to authenticate to GitHub with.
required: true
owner:
description: The owner of the package.
required: true
package_name:
description: The name of the package to query.
required: true
package_type:
description: 'The type of package to query (one of: npm, maven, rubygems, docker, nuget, container). Defaults to "container".'
required: false
default: container
greater_equal_version:
description: The minimum version to accept, e.g. 2.0.0. Defaults to None.
required: false
less_than_version:
description: The version to accept versions less than, e.g. 3.0.0. Defaults to None.
required: false
outputs:
tag:
description: The image tag for the latest version.
value: ${{ steps.get_version.outputs.tag }}
version:
description: The latest version number.
value: ${{ steps.get_version.outputs.version }}
runs:
using: composite
steps:
- name: Get Latest Version
id: get_version
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}
INPUT_greater_equal_version: ${{ inputs.greater_equal_version }}
INPUT_less_than_version: ${{ inputs.less_than_version }}
INPUT_owner: ${{ inputs.owner }}
INPUT_package_name: ${{ inputs.package_name }}
INPUT_package_type: ${{ inputs.package_type }}
INPUT_token: ${{ inputs.token }}
shell: python
run: |
from os import getenv
from os.path import abspath, join
import sys
sys.path.insert(1, abspath(join(getenv("GITHUB_ACTION_PATH", "."), "lib")))
from get_latest_version.github import get_latest_version_from_package
from get_latest_version.functions import clean_version
from semver import Version
greater_equal_version = None
if getenv("INPUT_greater_equal_version") is not None and len(getenv("INPUT_greater_equal_version")) >= 5:
greater_equal_version = Version.parse(getenv("INPUT_greater_equal_version"))
less_than_version = None
if getenv("INPUT_less_than_version") is not None and len(getenv("INPUT_less_than_version")) >= 5:
less_than_version = Version.parse(getenv("INPUT_less_than_version"))
tag = get_latest_version_from_package(
token=getenv("INPUT_token"),
owner=getenv("INPUT_owner"),
package_name=getenv("INPUT_package_name"),
package_type=getenv("INPUT_package_type"),
greater_equal_version=greater_equal_version,
less_than_version=less_than_version,
)
with open(getenv("GITHUB_OUTPUT"), "a", encoding="utf-8") as f:
f.write(f"tag={tag}\n")
f.write(f"version={Version.parse(clean_version(tag))}\n")
- name: Print Version
id: print
run: |
echo "Latest version of ${{ inputs.owner }}/${{ inputs.package_name }} is ${{ steps.get_version.outputs.version }} with tag ${{ steps.get_version.outputs.tag }}"
shell: bash
branding:
color: blue
icon: disc