Skip to content

Commit

Permalink
Add Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
aiKrice committed Dec 2, 2024
1 parent efc3c3d commit 9894875
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/badgetizr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ jobs:
uses: actions/checkout@v3

- name: Run Badgetizr
uses: aiKrice/homebrew-badgetizr@feat/support_github_action
uses: aiKrice/homebrew-badgetizr@feat/_support_github_action
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 }}"
pr_build_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 +75,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 Down Expand Up @@ -185,8 +209,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.
27 changes: 17 additions & 10 deletions deploy-homebrew.sh → publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# 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 +29,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 +42,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 9894875

Please sign in to comment.