Skip to content

Commit

Permalink
Update to v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gnpaone committed Aug 23, 2024
1 parent e6026ec commit 0046325
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4

- name: Winget Version Badge
uses: gnpaone/[email protected].2
uses: gnpaone/[email protected].3
with:
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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ An unofficial shields.io badge with package version fetched from custom API.

#### Notes for the workflow:
* 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`.
* Other parameters `commit_user`, `commit_email`, `commit_message` related to action workflow are optional.
* Other parameters `commit_user`, `commit_email`, `commit_message` and `confirm_and_push` related to action workflow are optional.
* 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`.
Expand All @@ -133,7 +133,7 @@ An unofficial shields.io badge with package version fetched from custom API.

## Usage
API calling example: `https://winget-version-badge.vercel.app/?id=Git.Git&image=true`<br>
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>
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>
<!-- EXAMPLE_1_START -->
[![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 -->
[![Git.Git](https://img.shields.io/badge/Winget%20package-2.46.0-green?style=plastic&labelColor=red)]()<!-- EXAMPLE_2_END -->
Expand Down
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ inputs:
description: "Git commit message"
default: "Update readme with latest winget version badge"
required: false
confirm_and_push:
description: "Push commits to Github repo"
default: "true"
required: false

outputs:
winget_ver:
description: "Winget package version"
git_username:
description: "Committer username"
git_email:
description: "Committer email"
commit_message:
description: "Commit message"

runs:
using: "docker"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4

- name: Winget Version Badge
uses: gnpaone/[email protected].2
uses: gnpaone/[email protected].3
with:
id: "Git.Git"
marker_text: "TEST_PKG"
2 changes: 1 addition & 1 deletion examples/multi-ver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4

- name: Winget Version Badge
uses: gnpaone/[email protected].2
uses: gnpaone/[email protected].3
with:
id: "GitHub.cli;Git.Git"
marker_text: "TEST_PKG_1;TEST_PKG_2"
Expand Down
68 changes: 68 additions & 0 deletions examples/pr-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Multiple badges update

on:
release:
types: [published]
workflow_dispatch:

jobs:
update-badge:
name: Update latest version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Winget Version Badge
uses: gnpaone/winget-version-badge@v1
with:
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"
confirm_and_push: "false"
id: latestver

- name: Create pull request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "${{ steps.latestver.outputs.commit_message }}"
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
branch: github-actions/repo-update
delete-branch: true
title: Update README

- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
- name: Enable pull request automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.PAT }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}

- name: Auto approve
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: juliangruber/approve-pull-request-action@v2
with:
github-token: ${{ secrets.PAT }}
number: ${{ steps.cpr.outputs.pull-request-number }}

- name: Version
run: |
version="${{ steps.latestver.outputs.winget_ver }}"
echo "ver=$version" >> $GITHUB_OUTPUT
IFS=';' read -r -a array <<< "$version"
for i in "${!array[@]}"; do
echo "ver$i=${array[$i]}" >> $GITHUB_OUTPUT
done
49 changes: 29 additions & 20 deletions winget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@

class Winget
def run
id = ENV['INPUT_ID']
style = ENV['INPUT_STYLE']
label = ENV['INPUT_LABEL'] || 'Winget package'
labelColor = ENV['INPUT_LABEL_COLOR']
color = ENV['INPUT_COLOR']
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, newline, html, readme_path, commit_message, git_username, git_email)
id = ENV['INPUT_ID']
style = ENV['INPUT_STYLE']
label = ENV['INPUT_LABEL'] || 'Winget package'
labelColor = ENV['INPUT_LABEL_COLOR']
color = ENV['INPUT_COLOR']
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'
confirm_and_push = ENV['INPUT_CONFIRM_AND_PUSH']

fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, commit_message, git_username, git_email, confirm_and_push)
rescue StandardError => e
puts "Error: #{e.message}"
exit 1
end

private

def fetch_winget(id, style, label, labelColor, color, marker_text, pkg_link, newline, html, readme_path, commit_message, git_username, git_email)
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)
id_array = id.split(';', -1)
marker_text_array = marker_text.split(';', -1)

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

def handle_param_array(param, id_length, param_name)
param_array = param.split(';', -1)
param_array = param.empty? ? [""] : param.split(';', -1)
if param_array.length == 1
Array.new(id_length, param_array[0])
elsif param_array.length == id_length
Expand Down Expand Up @@ -86,7 +87,7 @@ def handle_param_array(param, id_length, param_name)
file.puts("winget_ver=#{winget_ver}")
end

update_git_repo(readme_path, commit_message, git_username, git_email)
update_git_repo(readme_path, commit_message, git_username, git_email, confirm_and_push)
end

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

def update_git_repo(readme_path, commit_message, git_username, git_email)
def update_git_repo(readme_path, commit_message, git_username, git_email, confirm_and_push)
`git config --global --add safe.directory /github/workspace`
`git config user.name #{git_username}`
`git config user.email #{git_email}`
Expand All @@ -117,7 +118,15 @@ def update_git_repo(readme_path, commit_message, git_username, git_email)
unless status.include?("nothing to commit")
`git add #{readme_path}`
`git commit -m "#{commit_message}"`
`git push`
if confirm_and_push == "true"
`git push`
elsif confirm_and_push == "false"
File.open(ENV['GITHUB_OUTPUT'], 'a') do |file|
file.puts("git_username=#{git_username}")
file.puts("git_email=#{git_email}")
file.puts("commit_message=#{commit_message}")
end
end
end
end
end
Expand Down

0 comments on commit 0046325

Please sign in to comment.