Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
aiKrice committed Dec 3, 2024
2 parents d6c95fd + 4c4f782 commit fec3871
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 32 deletions.
28 changes: 19 additions & 9 deletions .badgetizr.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
badge_ci:
enabled: true
enabled: false
settings:
color: "purple"
label: "Bitrise"
Expand All @@ -8,11 +8,11 @@ badge_ci:
badge_ticket:
enabled: true
settings:
color: "blue"
label: "JIRA"
sed_pattern: '.*\(([^)]+)\).*'
url: "https://yourproject.atlassian.net/browse/%s"
logo: "jirasoftware"
color: "black"
label: "Github"
sed_pattern: '.*\[GH-([0-9]+)\].*'
url: "https://github.com/aiKrice/badgetizr/issues/%s"
logo: "github"

badge_base_branch:
enabled: true
Expand All @@ -35,10 +35,20 @@ badge_dynamic:
- badge_1:
pattern: "- [ ] Task 1"
label: "Task 1"
value: "Not done"
value: "Missing"
color: "orange"
- badge_2:
pattern: "- [x] Task 1"
label: "Task 1"
value: "Completed"
color: "forestgreen"
- badge_3:
pattern: "- [ ] Task 2"
label: "Task 2"
value: "Missing"
color: "orange"
- badge_3:
pattern: "- [x] Task 2"
label: "Task 2"
value: "Done"
color: "darkgreen"
value: "Completed"
color: "forestgreen"
29 changes: 29 additions & 0 deletions .github/workflows/badgetizr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run Badgetizr on Pull Requests

on:
pull_request:
types:
- opened
- reopened
- synchronize
- edited
- closed

jobs:
badgetizr:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v3

- name: Run Badgetizr
uses: aiKrice/[email protected]
with:
pr_id: ${{ github.event.pull_request.number }}
configuration: .badgetizr.yml
pr_destination_branch: ${{ github.event.pull_request.base.ref }}
pr_build_number: ${{ github.run_id }}
pr_build_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 31 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ _📣 I would like to put this tool available with Homebrew and Apt-Get. To succ
- [x] Add the tools to Homebrew tap
- [ ] Add the tool to Homebrew
- [ ] Add the tool to Apt-Get
- [ ] Add the tools to Github Actions
- [ ] Add the tools to Github Marketplace
- [x] Add the tools to Github Actions
- [ ] Support natively Gitlab with `glab` CLI

To see how to contribute, please refer to the section [Contributing](#contributing).
Expand Down Expand Up @@ -66,7 +65,7 @@ $ ./configure
```
In the rest of the documentation, I will consider that you have installed the tool in your `$PATH` and remove the `.sh` extension from the binary name.

## Usage
## Usage (CLI)
```bash
$ badgetizr #[options]
```
Expand All @@ -75,6 +74,30 @@ To see the different options available, you can use the `--help` option:
$ badgetizr --help
```

## Usage GithubAction
Instead of using the CLI, you can directly use the github action in your workflow.
```yaml
jobs:
badgetizr:
runs-on: ubuntu-latest #works also on macos-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v3

- name: Run Badgetizr
uses: aiKrice/[email protected]
with:
pr_id: ${{ github.event.pull_request.number }}
configuration: .badgetizr.yml
pr_destination_branch: ${{ github.event.pull_request.base.ref }}
pr_build_number: ${{ github.run_id }}
pr_build_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

```

## Configuration
By default, the configuration file used is `.badgetizr.yml`. You can also specify a configuration file to use by using the `-c` option.
```bash
Expand All @@ -93,7 +116,7 @@ If you want to use an icon for your badge, you can use the `icon` option and spe
#### Description

The badge ticket is a badge that will be displayed on your pull request if you have a Jira ticket or a Youtrack ticket in your pull request title or overall, something you would like to extract from the pull request title.
To do so, you have to define a pattern that will be used to extract the data (ie: ticket id). This pattern will be used with the `sed` command with the `-n -E` options and the `p` flag and will extract the first occurrence of the pattern found in the string.
To do so, you have to define a pattern that will be used to extract the data (ie: ticket id). This pattern will be used with the `sed` command with the `-n -E` options and the `p` flag and will extract the first occurrence of the pattern found in the string. Badgetizr will process the pattern like this: `sed -n -E "s/${ticket_badge_pattern}/\1/p"'`.

#### Configuration:
- `color`: The color of the badge (default: `blue`).
Expand Down Expand Up @@ -185,8 +208,9 @@ $ ./configure #optional, just for dependencies
$ ./badgetizer.sh
```

## Release (for maintainers)
To release the tool, you can run the `deploy-homebrew.sh` script by providing the version you want to release. Please respect the semantic versioning notation.
## Publishing (for maintainers)
To publish the tool, you can run the `publish.sh` script by providing the version you want to release. Please respect the semantic versioning notation.
```bash
./deploy-homebrew.sh 1.1.3
./publish.sh 1.1.3
```
This script will bump everything possible to keep everything up-to-date.
74 changes: 74 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: 'Badgetizr'
description: 'A GitHub Action to run Badgetizr for custom PR badges'
inputs:
pr_id:
description: 'Specify the path to the configuration. Default is .badgetizr.yml'
required: true
configuration:
description: 'The path to the configuration. Default is .badgetizr.yml'
required: false
default: '.badgetizr.yml'
pr_destination_branch:
description: '(Mandatory when branch badge is enabled) Specify the pull request destination branch'
required: false
pr_build_number:
description: '(Mandatory when CI badge is enabled) Specify the pull request build number'
required: false
pr_build_url:
description: '(Mandatory when CI badge is enabled) Specify the pull request build url'
required: false
runs:
using: 'composite'
steps:
- name: Install dependencies
run: |
if [[ "$(uname)" == "Darwin" ]]; then
echo "Running on macOS"
if ! command -v gh &> /dev/null; then
echo "GitHub CLI (gh) not found. Installing..."
brew install gh
fi
if ! command -v yq &> /dev/null; then
echo "yq not found. Installing..."
brew install yq
fi
else
echo "Running on Linux"
if ! command -v gh &> /dev/null; then
echo "GitHub CLI (gh) not found. Installing..."
sudo apt-get update
sudo apt-get install -y gh
fi
if ! command -v yq &> /dev/null; then
echo "yq not found. Installing..."
sudo apt-get install -y yq
fi
fi
shell: bash
- name: "Execute Badgetizr"
run: |
pr_id="${{ inputs.pr_id }}"
configuration="${{ inputs.configuration }}"
pr_destination_branch="${{ inputs.pr_destination_branch }}"
pr_build_number="${{ inputs.pr_build_number }}"
pr_build_url="${{ inputs.pr_build_url }}"
options=""
if [ -n "$pr_id" ]; then
options="$options --pr-id=$pr_id"
fi
if [ -n "$pr_destination_branch" ]; then
options="$options --pr-destination-branch $pr_destination_branch"
fi
if [ -n "$pr_build_number" ]; then
options="$options --pr-build-number $pr_build_number"
fi
if [ -n "$pr_build_url" ]; then
options="$options --pr-build-url $pr_build_url"
fi
chmod +x ./badgetizr.sh
./badgetizr.sh -c $configuration $options
shell: bash
12 changes: 7 additions & 5 deletions badgetizr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Usage: $0 [options]
Options :
-c <file>,
--configuration=<file>,
--configuration <file> (Optional) Specify a configuration file. By default, the configuration file used is : .badgetizr.yml
--configuration <file> (Optional) Specify the path to the configuration. Default is .badgetizr.yml
--pr-id=<id>,
--pr-id <id> (Mandatory) Specify the pull request id.
Expand Down Expand Up @@ -156,14 +156,16 @@ pull_request_body=$(echo "$pull_request_body" | awk '/<!--begin:badgetizr-->/ {f

all_badges=

#Jira Badge
#Ticket Badge
if [ "$ticket_badge_enabled" = "true" ]; then
ticket_id=$(echo "$pull_request_title" | sed -n -E "s/${ticket_badge_pattern}/\1/p")
ticket_badge_url=$(printf "$ticket_badge_url" "$ticket_id")
if [[ -n "$ticket_id" ]]; then
if [[ -z "$ticket_id" ]]; then
echo "🟠 No ticket id identified in the PR title. Maybe your pattern is not correct."
else
echo "🟡 Ticket id identified is -> $ticket_id"
ticket_badge_url_for_badge=$(printf "$ticket_badge_url" "$ticket_id")
ticket_id_for_badge=$(echo $ticket_id | sed -E 's/ /_/g; s/-/--/g')
ticket_badge="[![Static Badge](https://img.shields.io/badge/$ticket_badge_label-$ticket_id_for_badge-$ticket_badge_color?logo=$ticket_badge_logo&color=$ticket_badge_color&labelColor=grey)]($ticket_badge_url)"
ticket_badge="[![Static Badge](https://img.shields.io/badge/$ticket_badge_label-$ticket_id_for_badge-$ticket_badge_color?logo=$ticket_badge_logo&color=$ticket_badge_color&labelColor=grey)]($ticket_badge_url_for_badge)"
all_badges=$all_badges$ticket_badge
fi
fi
Expand Down
Binary file modified badgetizr_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 21 additions & 11 deletions deploy-homebrew.sh → publish.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/bin/bash

# The script deploy-homebrew.sh is used to release the tool to the homebrew repository.
# The script publish.sh is usefull to:
# - Generate the sha256 for Homebrew formula
# - Update the workflow with the right new version
# - Update the Readme.md for the best developer experience during integration
# It will create a tag, update the formula and create a PR.

# Configuration
REPOSITORY="aiKrice/homebrew-badgetizr"
FORMULA_PATH="Formula/badgetizr.rb"
WORKFLOW_PATH=".github/workflows/badgetizr.yml"
README_PATH="README.md"
VERSION="$1"

red='\033[1;31m'
Expand All @@ -27,7 +32,7 @@ function fail_if_error() {
}

if [ -z "$VERSION" ]; then
echo "❌ Please provide a version (example: ./release.sh 1.1.3). Please respect the semantic versioning notation."
echo "❌ Please provide a version (example: ./release.sh ${cyan}1.1.3${reset}). Please respect the semantic versioning notation."
exit 1
fi

Expand All @@ -40,35 +45,40 @@ fail_if_error "Failed to merge develop into master"
echo "🟢 [Step 1/5] Master is updated."
git push --no-verify

echo "🟡 [Step 2/5] Creating the release tag..."
echo "🟡 [Step 2/5] Creating the release tag ${cyan}$VERSION${reset}..."
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION" --no-verify
gh release create $VERSION --generate-notes --verify-tag
echo "🟢 [Step 2/5] Github release created"

# Step 2: Download the archive and calculate SHA256 for Homebrew
echo "🟡 [Step 3/5] Downloading the archive..."
ARCHIVE_URL="https://github.com/$REPOSITORY/archive/refs/tags/$VERSION.tar.gz"
echo "🟡 [Step 3/5] Downloading the archive $ARCHIVE_URL..."

curl -L -o "badgetizr-$VERSION.tar.gz" "$ARCHIVE_URL" > /dev/null
fail_if_error "Failed to download the archive"
echo "🟢 [Step 3/5] Archive downloaded."
SHA256=$(shasum -a 256 "badgetizr-$VERSION.tar.gz" | awk '{print $1}')
echo "🟢 SHA256 generated: $SHA256"
echo "🟢 SHA256 generated: ${cyan}$SHA256${reset}"

# Step 3: Update the formula
sed -i "" -E \
-e "s#(url \").*(\".*)#\1$ARCHIVE_URL\2#" \
-e "s#(sha256 \").*(\".*)#\1$SHA256\2#" \
"$FORMULA_PATH"

# Step 3bis: Update the workflow with new version number
sed -i '' "s|uses: aiKrice/homebrew-badgetizr@.*|uses: aiKrice/homebrew-badgetizr@${NEW_VERSION}|" "$WORKFLOW_FILE"

# Step 4: Commit and push
echo "🟡 [Step 4/5] Committing the formula..."
git add "$FORMULA_PATH"
git commit -m "Update formula for version $VERSION"
fail_if_error "Failed to commit the formula"
echo "🟡 [Step 4/5] Commiting the bump of the files..."
git add "$FORMULA_PATH" "$WORKFLOW_PATH"
git commit -m "Bump version $VERSION"
fail_if_error "Failed to commit the bump"
git push --no-verify
fail_if_error "Failed to push the formula"
echo "🟢 [Step 4/5] Formula pushed."
fail_if_error "Failed to push the bump"
echo "🟢 [Step 4/5] Bump pushed."

# Step 5: Backmerge to develop
echo "🟡 [Step 5/5] Switching to develop..."
git switch develop
Expand Down

0 comments on commit fec3871

Please sign in to comment.