Skip to content

Commit 0046325

Browse files
committed
Update to v1.0.3
1 parent e6026ec commit 0046325

File tree

7 files changed

+113
-25
lines changed

7 files changed

+113
-25
lines changed

.github/workflows/example.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v4
1515

1616
- name: Winget Version Badge
17-
uses: gnpaone/[email protected].2
17+
uses: gnpaone/[email protected].3
1818
with:
1919
id: "GitHub.cli;Git.Git;Git.MinGit;GitHub.GitHubDesktop;GitHub.GitLFS;Gitleaks.Gitleaks"
2020
marker_text: "EXAMPLE_1;EXAMPLE_2;EXAMPLE_3;EXAMPLE_4;EXAMPLE_5;EXAMPLE_6"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ An unofficial shields.io badge with package version fetched from custom API.
122122

123123
#### Notes for the workflow:
124124
* Make sure to change the following in your GitHub repo settings: `Actions` > `General` > `Workflow permissions` > Choose `Read and write permissions` > Check `Allow GitHub Actions to create and approve pull requests` > `Save`.
125-
* Other parameters `commit_user`, `commit_email`, `commit_message` related to action workflow are optional.
125+
* Other parameters `commit_user`, `commit_email`, `commit_message` and `confirm_and_push` related to action workflow are optional.
126126
* For fetching multiple package versions
127127
* `id` and `marker_text` must contain equal number of elements.
128128
* 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`.
@@ -133,7 +133,7 @@ An unofficial shields.io badge with package version fetched from custom API.
133133

134134
## Usage
135135
API calling example: `https://winget-version-badge.vercel.app/?id=Git.Git&image=true`<br>
136-
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) <br>
136+
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) | [PR only worflow](https://github.com/gnpaone/winget-version-badge/blob/main/examples/pr-only.yml) <br>
137137
<!-- EXAMPLE_1_START -->
138138
[![GitHub.cli](https://img.shields.io/badge/Winget%20package-2.9.0-blue?style=plastic&labelColor=)](https://github.com)<!-- EXAMPLE_1_END --><!-- EXAMPLE_2_START -->
139139
[![Git.Git](https://img.shields.io/badge/Winget%20package-2.46.0-green?style=plastic&labelColor=red)]()<!-- EXAMPLE_2_END -->

action.yml

+11
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,20 @@ inputs:
5252
description: "Git commit message"
5353
default: "Update readme with latest winget version badge"
5454
required: false
55+
confirm_and_push:
56+
description: "Push commits to Github repo"
57+
default: "true"
58+
required: false
59+
5560
outputs:
5661
winget_ver:
5762
description: "Winget package version"
63+
git_username:
64+
description: "Committer username"
65+
git_email:
66+
description: "Committer email"
67+
commit_message:
68+
description: "Commit message"
5869

5970
runs:
6071
using: "docker"

examples/basic.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v4
1515

1616
- name: Winget Version Badge
17-
uses: gnpaone/[email protected].2
17+
uses: gnpaone/[email protected].3
1818
with:
1919
id: "Git.Git"
2020
marker_text: "TEST_PKG"

examples/multi-ver.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v4
1515

1616
- name: Winget Version Badge
17-
uses: gnpaone/[email protected].2
17+
uses: gnpaone/[email protected].3
1818
with:
1919
id: "GitHub.cli;Git.Git"
2020
marker_text: "TEST_PKG_1;TEST_PKG_2"

examples/pr-only.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Multiple badges update
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-badge:
10+
name: Update latest version
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Winget Version Badge
17+
uses: gnpaone/winget-version-badge@v1
18+
with:
19+
id: "GitHub.cli;Git.Git"
20+
marker_text: "TEST_PKG_1;TEST_PKG_2"
21+
pkg_link: "https://github.com;"
22+
label: "Winget package"
23+
label_color: ";red"
24+
color: "blue;green"
25+
confirm_and_push: "false"
26+
id: latestver
27+
28+
- name: Create pull request
29+
id: cpr
30+
uses: peter-evans/create-pull-request@v6
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
commit-message: "${{ steps.latestver.outputs.commit_message }}"
34+
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
35+
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
36+
branch: github-actions/repo-update
37+
delete-branch: true
38+
title: Update README
39+
40+
- name: Check outputs
41+
if: ${{ steps.cpr.outputs.pull-request-number }}
42+
run: |
43+
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
44+
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
45+
46+
- name: Enable pull request automerge
47+
if: steps.cpr.outputs.pull-request-operation == 'created'
48+
uses: peter-evans/enable-pull-request-automerge@v3
49+
with:
50+
token: ${{ secrets.PAT }}
51+
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
52+
53+
- name: Auto approve
54+
if: steps.cpr.outputs.pull-request-operation == 'created'
55+
uses: juliangruber/approve-pull-request-action@v2
56+
with:
57+
github-token: ${{ secrets.PAT }}
58+
number: ${{ steps.cpr.outputs.pull-request-number }}
59+
60+
- name: Version
61+
run: |
62+
version="${{ steps.latestver.outputs.winget_ver }}"
63+
echo "ver=$version" >> $GITHUB_OUTPUT
64+
IFS=';' read -r -a array <<< "$version"
65+
for i in "${!array[@]}"; do
66+
echo "ver$i=${array[$i]}" >> $GITHUB_OUTPUT
67+
done
68+

winget.rb

+29-20
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,30 @@
66

77
class Winget
88
def run
9-
id = ENV['INPUT_ID']
10-
style = ENV['INPUT_STYLE']
11-
label = ENV['INPUT_LABEL'] || 'Winget package'
12-
labelColor = ENV['INPUT_LABEL_COLOR']
13-
color = ENV['INPUT_COLOR']
14-
readme_path = ENV['INPUT_README_PATH']
15-
marker_text = ENV['INPUT_MARKER_TEXT']
16-
pkg_link = ENV['INPUT_PKG_LINK']
17-
newline = ENV['INPUT_NEWLINE']
18-
html = ENV['INPUT_HTML']
19-
git_username = ENV['INPUT_COMMIT_USER']
20-
git_email = ENV['INPUT_COMMIT_EMAIL']
21-
commit_message = ENV['INPUT_COMMIT_MESSAGE'] || 'Update README.md'
22-
23-
fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, commit_message, git_username, git_email)
9+
id = ENV['INPUT_ID']
10+
style = ENV['INPUT_STYLE']
11+
label = ENV['INPUT_LABEL'] || 'Winget package'
12+
labelColor = ENV['INPUT_LABEL_COLOR']
13+
color = ENV['INPUT_COLOR']
14+
readme_path = ENV['INPUT_README_PATH']
15+
marker_text = ENV['INPUT_MARKER_TEXT']
16+
pkg_link = ENV['INPUT_PKG_LINK']
17+
newline = ENV['INPUT_NEWLINE']
18+
html = ENV['INPUT_HTML']
19+
git_username = ENV['INPUT_COMMIT_USER']
20+
git_email = ENV['INPUT_COMMIT_EMAIL']
21+
commit_message = ENV['INPUT_COMMIT_MESSAGE'] || 'Update README.md'
22+
confirm_and_push = ENV['INPUT_CONFIRM_AND_PUSH']
23+
24+
fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, commit_message, git_username, git_email, confirm_and_push)
2425
rescue StandardError => e
2526
puts "Error: #{e.message}"
2627
exit 1
2728
end
2829

2930
private
3031

31-
def fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, commit_message, git_username, git_email)
32+
def fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, commit_message, git_username, git_email, confirm_and_push)
3233
id_array = id.split(';', -1)
3334
marker_text_array = marker_text.split(';', -1)
3435

@@ -38,7 +39,7 @@ def fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, new
3839
end
3940

4041
def handle_param_array(param, id_length, param_name)
41-
param_array = param.split(';', -1)
42+
param_array = param.empty? ? [""] : param.split(';', -1)
4243
if param_array.length == 1
4344
Array.new(id_length, param_array[0])
4445
elsif param_array.length == id_length
@@ -86,7 +87,7 @@ def handle_param_array(param, id_length, param_name)
8687
file.puts("winget_ver=#{winget_ver}")
8788
end
8889

89-
update_git_repo(readme_path, commit_message, git_username, git_email)
90+
update_git_repo(readme_path, commit_message, git_username, git_email, confirm_and_push)
9091
end
9192

9293
def update_readme_content(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, winget_ver)
@@ -108,7 +109,7 @@ def update_readme_content(id, style, label, labelColor, color, marker_text, pkg_
108109
File.write(readme_path, updated_readme_content)
109110
end
110111

111-
def update_git_repo(readme_path, commit_message, git_username, git_email)
112+
def update_git_repo(readme_path, commit_message, git_username, git_email, confirm_and_push)
112113
`git config --global --add safe.directory /github/workspace`
113114
`git config user.name #{git_username}`
114115
`git config user.email #{git_email}`
@@ -117,7 +118,15 @@ def update_git_repo(readme_path, commit_message, git_username, git_email)
117118
unless status.include?("nothing to commit")
118119
`git add #{readme_path}`
119120
`git commit -m "#{commit_message}"`
120-
`git push`
121+
if confirm_and_push == "true"
122+
`git push`
123+
elsif confirm_and_push == "false"
124+
File.open(ENV['GITHUB_OUTPUT'], 'a') do |file|
125+
file.puts("git_username=#{git_username}")
126+
file.puts("git_email=#{git_email}")
127+
file.puts("commit_message=#{commit_message}")
128+
end
129+
end
121130
end
122131
end
123132
end

0 commit comments

Comments
 (0)