From e6026ec522f75a05d72d8b80b386d6011f6c37dc Mon Sep 17 00:00:00 2001
From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com>
Date: Fri, 23 Aug 2024 15:37:18 +0530
Subject: [PATCH] Update to v1.0.2 with added features
---
.github/workflows/example.yml | 18 ++++++++++--------
README.md | 32 ++++++++++++++++++++++++++-----
action.yml | 8 ++++++++
examples/basic.yml | 2 +-
examples/multi-ver.yml | 18 +++++++++---------
winget.rb | 36 +++++++++++++++++++++++------------
6 files changed, 79 insertions(+), 35 deletions(-)
diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml
index 40d65b8..69df4c7 100644
--- a/.github/workflows/example.yml
+++ b/.github/workflows/example.yml
@@ -14,22 +14,24 @@ jobs:
uses: actions/checkout@v4
- name: Winget Version Badge
- uses: gnpaone/winget-version-badge@v1.0.0
+ uses: gnpaone/winget-version-badge@v1.0.2
with:
- id: "GitHub.cli,Git.Git"
- marker_text: "EXAMPLE_1,EXAMPLE_2"
- pkg_link: "https://github.com,"
+ id: "GitHub.cli;Git.Git;Git.MinGit;GitHub.GitHubDesktop;GitHub.GitLFS;Gitleaks.Gitleaks"
+ marker_text: "EXAMPLE_1;EXAMPLE_2;EXAMPLE_3;EXAMPLE_4;EXAMPLE_5;EXAMPLE_6"
+ pkg_link: "https://github.com;;;;https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage;"
style: "plastic"
- label_color: ",red"
- color: "blue,green"
+ label_color: ";red;orange;cyan;;"
+ color: "blue;green;yellow;eb4034;hsl(72, 100%, 50%);rgb(255, 0, 153, 1)"
+ newline: "true;true;false;false;false;true"
+ html: "false;false;false;false;false;true"
id: latestver
# Optional
- name: Version
run: |
- version=${{ steps.latestver.outputs.winget_ver }}
+ version="${{ steps.latestver.outputs.winget_ver }}"
echo "ver=$version" >> $GITHUB_OUTPUT
- IFS=',' read -r -a array <<< "$version"
+ IFS=';' read -r -a array <<< "$version"
for i in "${!array[@]}"; do
echo "ver$i=${array[$i]}" >> $GITHUB_OUTPUT
done
diff --git a/README.md b/README.md
index 0216911..ab45ae5 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,7 @@ An unofficial shields.io badge with package version fetched from custom API.
Package id - can be found using winget search |
Yes |
Winget package identifier (ID) |
- All these parameters (related to workflow only) supports updating multiple package badges at a time without calling the workflow multiple times. Example workflow |
+ All these parameters (related to workflow only) supports updating multiple package badges at a time without calling the workflow multiple times. Example workflow |
style |
@@ -73,7 +73,7 @@ An unofficial shields.io badge with package version fetched from custom API.
N/A |
image |
false |
- Return version as shields.io badge oor just as plain text |
+ Return version as shields.io badge or just as plain text |
No |
true or 1, false |
@@ -101,6 +101,22 @@ An unofficial shields.io badge with package version fetched from custom API.
No |
URL of the package repo |
+
+ newline |
+ N/A |
+ true |
+ Add \n after start marker (n/a when html parameter is true) |
+ No |
+ true, false |
+
+
+ html |
+ N/A |
+ false |
+ Return badge as html instead of markdown text |
+ No |
+ true, false |
+
@@ -110,17 +126,23 @@ An unofficial shields.io badge with package version fetched from custom API.
* For fetching multiple package versions
* `id` and `marker_text` must contain equal number of elements.
* Other parameters can either be single element which applies to all the multiple badges or number of elements must be equal to `id` and `marker_text`.
- * The multiple elements should be comma separated and overall wrapped in double quotes.
+ * The multiple elements should be semicolon separated and overall wrapped in double quotes.
* Empty elements are allowed for `style`, `label_color` and `pkg_link` parameters only.
* The README markdown file must contain start marker `` and end marker `` where "EXAMPLE_MARKER" is the input of `marker_text` parameter. Note that the `_START` and `_END` part is important.
-* The fetched versions can be accessed via `outputs.winget_ver` for further usage in the workflow. If multiple versions are fetched then this contains versions separated with ",".
+* The fetched versions can be accessed via `outputs.winget_ver` for further usage in the workflow. If multiple versions are fetched then this contains versions separated with ";".
## Usage
API calling example: `https://winget-version-badge.vercel.app/?id=Git.Git&image=true`
Workflow examples: [Basic workflow](https://github.com/gnpaone/winget-version-badge/blob/main/examples/basic.yml) | [Multi versions](https://github.com/gnpaone/winget-version-badge/blob/main/examples/multi-ver.yml)
[![GitHub.cli](https://img.shields.io/badge/Winget%20package-2.9.0-blue?style=plastic&labelColor=)](https://github.com)
-[![Git.Git](https://img.shields.io/badge/Winget%20package-2.46.0-green?style=plastic&labelColor=red)](https://github.com)
+[![Git.Git](https://img.shields.io/badge/Winget%20package-2.46.0-green?style=plastic&labelColor=red)]()
+
+|EXAMPLE_3|EXAMPLE_4|EXAMPLE_5|
+|:----:|:----:|:----:|
+|[![Git.MinGit](https://img.shields.io/badge/Winget%20package-2.45.0-yellow?style=plastic&labelColor=orange)]()|[![GitHub.GitHubDesktop](https://img.shields.io/badge/Winget%20package-3.4.3-eb4034?style=plastic&labelColor=cyan)]()|[![GitHub.GitLFS](https://img.shields.io/badge/Winget%20package-3.4.1-hsl%2872%2C%20100%25%2C%2050%25%29?style=plastic&labelColor=)](https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage)|
+
+
## Limitations
- Since deployed in Vercel, all its limitations applied. Thus it is requested not to abuse the API usage and push it to limits.
diff --git a/action.yml b/action.yml
index ea6be1b..541a716 100644
--- a/action.yml
+++ b/action.yml
@@ -32,6 +32,14 @@ inputs:
description: "Winget package repo link"
default: ""
required: false
+ newline:
+ description: 'Add \n after start marker'
+ default: "true"
+ required: false
+ html:
+ description: 'Return badge as html instead of markdown text'
+ default: "false"
+ required: false
commit_user:
description: "Git username"
default: "winget-badge-bot"
diff --git a/examples/basic.yml b/examples/basic.yml
index 3b19549..a3efdc1 100644
--- a/examples/basic.yml
+++ b/examples/basic.yml
@@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4
- name: Winget Version Badge
- uses: gnpaone/winget-version-badge@v1.0.0
+ uses: gnpaone/winget-version-badge@v1.0.2
with:
id: "Git.Git"
marker_text: "TEST_PKG"
diff --git a/examples/multi-ver.yml b/examples/multi-ver.yml
index aeaad30..ffe8495 100644
--- a/examples/multi-ver.yml
+++ b/examples/multi-ver.yml
@@ -14,22 +14,22 @@ jobs:
uses: actions/checkout@v4
- name: Winget Version Badge
- uses: gnpaone/winget-version-badge@v1.0.0
+ uses: gnpaone/winget-version-badge@v1.0.2
with:
- id: "GitHub.cli,Git.Git"
- marker_text: "TEST_PKG_1,TEST_PKG_2"
- pkg_link: "https://github.com,"
+ id: "GitHub.cli;Git.Git"
+ marker_text: "TEST_PKG_1;TEST_PKG_2"
+ pkg_link: "https://github.com;"
label: "Winget package"
- label_color: ",red"
- color: "blue,green"
+ label_color: ";red"
+ color: "blue;green"
id: latestver
- name: Version
run: |
- version=${{ steps.latestver.outputs.winget_ver }}
+ version="${{ steps.latestver.outputs.winget_ver }}"
echo "ver=$version" >> $GITHUB_OUTPUT
- IFS=',' read -r -a array <<< "$version"
+ IFS=';' read -r -a array <<< "$version"
for i in "${!array[@]}"; do
echo "ver$i=${array[$i]}" >> $GITHUB_OUTPUT
done
-
+
\ No newline at end of file
diff --git a/winget.rb b/winget.rb
index 5950fdb..c99a3ac 100644
--- a/winget.rb
+++ b/winget.rb
@@ -14,11 +14,13 @@ def run
readme_path = ENV['INPUT_README_PATH']
marker_text = ENV['INPUT_MARKER_TEXT']
pkg_link = ENV['INPUT_PKG_LINK']
+ newline = ENV['INPUT_NEWLINE']
+ html = ENV['INPUT_HTML']
git_username = ENV['INPUT_COMMIT_USER']
git_email = ENV['INPUT_COMMIT_EMAIL']
commit_message = ENV['INPUT_COMMIT_MESSAGE'] || 'Update README.md'
- fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, readme_path, commit_message, git_username, git_email)
+ fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, commit_message, git_username, git_email)
rescue StandardError => e
puts "Error: #{e.message}"
exit 1
@@ -26,9 +28,9 @@ def run
private
- def fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, readme_path, commit_message, git_username, git_email)
- id_array = id.split(',')
- marker_text_array = marker_text.split(',')
+ def fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, commit_message, git_username, git_email)
+ id_array = id.split(';', -1)
+ marker_text_array = marker_text.split(';', -1)
if id_array.length != marker_text_array.length
puts "Error: 'id' and 'marker_text' must have the same array length."
@@ -36,7 +38,7 @@ def fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, rea
end
def handle_param_array(param, id_length, param_name)
- param_array = param.split(',')
+ param_array = param.split(';', -1)
if param_array.length == 1
Array.new(id_length, param_array[0])
elsif param_array.length == id_length
@@ -53,6 +55,8 @@ def handle_param_array(param, id_length, param_name)
color_array = handle_param_array(color, id_array.length, 'color')
readme_path_array = handle_param_array(readme_path, id_array.length, 'readme_path')
pkg_link_array = handle_param_array(pkg_link, id_array.length, 'pkg_link')
+ newline_array = handle_param_array(newline, id_array.length, 'newline')
+ html_array = handle_param_array(html, id_array.length, 'html')
winget_ver_array = Array.new(id_array.length)
@@ -69,14 +73,14 @@ def handle_param_array(param, id_length, param_name)
pkg_ver = URI.open(api_url).read
winget_ver_array[i] = pkg_ver
- update_readme_content(id_array[i], style_array[i], label_array[i], labelColor_array[i], color_array[i], marker_text_array[i], pkg_link_array[i], readme_path_array[i], pkg_ver)
+ update_readme_content(id_array[i], style_array[i], label_array[i], labelColor_array[i], color_array[i], marker_text_array[i], pkg_link_array[i], newline_array[i], html_array[i], readme_path_array[i], pkg_ver)
else
puts "Failed to retrieve: #{id_array[i]} - #{response.code} - #{response.message}"
exit 1
end
end
- winget_ver = winget_ver_array.join(',')
+ winget_ver = winget_ver_array.join(';')
File.open(ENV['GITHUB_OUTPUT'], 'a') do |file|
file.puts("winget_ver=#{winget_ver}")
@@ -85,13 +89,21 @@ def handle_param_array(param, id_length, param_name)
update_git_repo(readme_path, commit_message, git_username, git_email)
end
- def update_readme_content(id, style, label, labelColor, color, marker_text, pkg_link, readme_path, winget_ver)
+ def update_readme_content(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, winget_ver)
readme_content = File.read(readme_path)
start_marker = ""
end_marker = ""
- shields_url = "https://img.shields.io/badge/#{ERB::Util.url_encode(label)}-#{winget_ver}-#{color}?style=#{style}&labelColor=#{labelColor}"
-
- updated_readme_content = readme_content.gsub(/#{start_marker}.*#{end_marker}/m, "#{start_marker}\n[![#{id}](#{shields_url})](#{pkg_link})#{end_marker}")
+ shields_url = "https://img.shields.io/badge/#{ERB::Util.url_encode(label)}-#{winget_ver}-#{ERB::Util.url_encode(color)}?style=#{style}&labelColor=#{ERB::Util.url_encode(labelColor)}"
+
+ if html=="true"
+ updated_readme_content = readme_content.gsub(/#{start_marker}.*#{end_marker}/m, "#{start_marker}#{end_marker}")
+ elsif html=="false"
+ if newline=="true"
+ updated_readme_content = readme_content.gsub(/#{start_marker}.*#{end_marker}/m, "#{start_marker}\n[![#{id}](#{shields_url})](#{pkg_link})#{end_marker}")
+ elsif newline=="false"
+ updated_readme_content = readme_content.gsub(/#{start_marker}.*#{end_marker}/m, "#{start_marker}[![#{id}](#{shields_url})](#{pkg_link})#{end_marker}")
+ end
+ end
File.write(readme_path, updated_readme_content)
end
@@ -110,4 +122,4 @@ def update_git_repo(readme_path, commit_message, git_username, git_email)
end
end
-Winget.new.run
+Winget.new.run
\ No newline at end of file