|
1 |
| -name: Update Homebrew Tap on Release |
| 1 | +name: Update Homebrew Formula |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | release:
|
5 | 5 | types: [published]
|
| 6 | + |
6 | 7 | workflow_dispatch:
|
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: "Release tag to update the formula (e.g., 'v2.0.12')" |
| 11 | + required: false |
| 12 | + default: "2.0.11" |
7 | 13 |
|
8 | 14 | jobs:
|
9 |
| - homebrew-releaser: |
| 15 | + update-formula: |
10 | 16 | runs-on: ubuntu-latest
|
| 17 | + |
11 | 18 | steps:
|
12 |
| - - name: Release project to Homebrew tap |
13 |
| - uses: Justintime50/homebrew-releaser@v2 |
| 19 | + - name: Extract version from input or release |
| 20 | + id: extract_version |
| 21 | + run: | |
| 22 | + # Use the provided tag if triggered manually, otherwise use the release tag |
| 23 | + if [ "${{ github.event.inputs.tag }}" != "" ]; then |
| 24 | + VERSION="${{ github.event.inputs.tag }}" |
| 25 | + else |
| 26 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 27 | + fi |
| 28 | +
|
| 29 | + # Normalize by removing a leading 'v' if present |
| 30 | + VERSION="${VERSION#v}" |
| 31 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 32 | +
|
| 33 | + - name: Find jar asset download URL |
| 34 | + id: find_asset |
| 35 | + run: | |
| 36 | + # Get release data from GitHub API |
| 37 | + release_data=$(curl -sL -H "Accept: application/vnd.github+json" \ |
| 38 | + "https://api.github.com/repos/skidfuscatordev/skidfuscator-java-obfuscator/releases/tags/${{ steps.extract_version.outputs.version }}") |
| 39 | +
|
| 40 | + # Find the asset named 'skidfuscator.jar' (adjust if needed) |
| 41 | + asset_url=$(echo "$release_data" | jq -r '.assets[] | select(.name == "skidfuscator.jar") | .browser_download_url') |
| 42 | +
|
| 43 | + if [ -z "$asset_url" ]; then |
| 44 | + echo "Could not find skidfuscator.jar in the release." |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | +
|
| 48 | + echo "asset_url=$asset_url" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + - name: Download jar |
| 51 | + run: | |
| 52 | + curl -L ${{ steps.find_asset.outputs.asset_url }} -o skidfuscator.jar |
| 53 | +
|
| 54 | + - name: Compute SHA256 |
| 55 | + id: sha256 |
| 56 | + run: | |
| 57 | + SHA256=$(shasum -a 256 skidfuscator.jar | awk '{print $1}') |
| 58 | + echo "sha256=$SHA256" >> $GITHUB_OUTPUT |
| 59 | +
|
| 60 | + - name: Checkout tap repository |
| 61 | + uses: actions/checkout@v3 |
14 | 62 | with:
|
15 |
| - # The owner and tap name of your Homebrew tap repository |
16 |
| - homebrew_owner: skidfuscatordev |
17 |
| - homebrew_tap: homebrew-skidfuscator |
18 |
| - |
19 |
| - # Required Personal Access Token secret with `repo` permissions |
20 |
| - github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
21 |
| - |
22 |
| - # The `install` block is Ruby code inserted into the formula. |
23 |
| - # We'll: |
24 |
| - # 1. Install any JAR in the release into libexec |
25 |
| - # 2. Create a wrapper script in bin/ to run it |
26 |
| - install: | |
27 |
| - libexec.install Dir["*.jar"] |
28 |
| - jar_name = Dir["#{libexec}/*.jar"].first |
29 |
| - (bin/"skidfuscator").write <<~EOS |
30 |
| - #!/usr/bin/env bash |
31 |
| - exec java -jar "#{jar_name}" "$@" |
32 |
| - EOS |
33 |
| - (bin/"skidfuscator").chmod 0755 |
34 |
| -
|
35 |
| - # A basic test block: checks if 'skidfuscator --help' prints usage |
36 |
| - test: 'assert_match("Usage", shell_output("#{bin}/skidfuscator --help", 0))' |
37 |
| - |
38 |
| - # Optional dependencies (if needed). For Skidfuscator, typically just Java. |
39 |
| - # If the user must have Java installed, you can specify: |
40 |
| - |
41 |
| - # We do not need to set version explicitly if releases are semver-tagged. |
42 |
| - # The action will infer version from the tag (e.g., v2.0.11). |
43 |
| - |
44 |
| - # No need to update README with a project table or debug here |
45 |
| - update_readme_table: false |
46 |
| - debug: false |
| 63 | + repository: your-username/homebrew-skidfuscator |
| 64 | + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 65 | + # Use a branch name where the formula resides, usually 'main' |
| 66 | + ref: main |
| 67 | + |
| 68 | + - name: Update formula |
| 69 | + run: | |
| 70 | + FORMULA_PATH="Formula/skidfuscator.rb" |
| 71 | + NEW_VERSION="${{ steps.extract_version.outputs.version }}" |
| 72 | + NEW_URL="${{ steps.find_asset.outputs.asset_url }}" |
| 73 | + NEW_SHA256="${{ steps.sha256.outputs.sha256 }}" |
| 74 | +
|
| 75 | + # Update url line |
| 76 | + sed -i.bak "s|^ url \".*\"| url \"${NEW_URL}\"|" $FORMULA_PATH |
| 77 | + # Update sha256 line |
| 78 | + sed -i.bak "s|^ sha256 \".*\"| sha256 \"${NEW_SHA256}\"|" $FORMULA_PATH |
| 79 | + # Update version line |
| 80 | + sed -i.bak "s|^ version \".*\"| version \"${NEW_VERSION}\"|" $FORMULA_PATH |
| 81 | +
|
| 82 | + # Clean backup |
| 83 | + rm $FORMULA_PATH.bak |
| 84 | +
|
| 85 | + echo "Updated formula with version=${NEW_VERSION}, url=${NEW_URL}, sha256=${NEW_SHA256}" |
| 86 | + cat $FORMULA_PATH |
| 87 | +
|
| 88 | + - name: Commit and push changes |
| 89 | + run: | |
| 90 | + git config user.name "github-actions" |
| 91 | + git config user.email "[email protected]" |
| 92 | + git add Formula/skidfuscator.rb |
| 93 | + git commit -m "Update Skidfuscator formula to version ${{ steps.extract_version.outputs.version }}" |
| 94 | + git push origin HEAD:main |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
0 commit comments