|
| 1 | +name: Update Homebrew Formula |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 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" |
| 13 | + |
| 14 | +jobs: |
| 15 | + update-formula: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Extract version from input or release |
| 19 | + id: extract_version |
| 20 | + run: | |
| 21 | + # Use the provided tag if triggered manually, otherwise use the release tag |
| 22 | + if [ "${{ github.event.inputs.tag }}" != "" ]; then |
| 23 | + VERSION="${{ github.event.inputs.tag }}" |
| 24 | + else |
| 25 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 26 | + fi |
| 27 | +
|
| 28 | + # Normalize by removing a leading 'v' if present |
| 29 | + VERSION="${VERSION#v}" |
| 30 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 31 | +
|
| 32 | + - name: Find jar asset download URL |
| 33 | + id: find_asset |
| 34 | + run: | |
| 35 | + # Get release data from GitHub API |
| 36 | + release_data=$(curl -sL -H "Accept: application/vnd.github+json" \ |
| 37 | + "https://api.github.com/repos/skidfuscatordev/skidfuscator-java-obfuscator/releases/tags/${{ steps.extract_version.outputs.version }}") |
| 38 | +
|
| 39 | + # Find the asset named 'skidfuscator.jar' (adjust if needed) |
| 40 | + asset_url=$(echo "$release_data" | jq -r '.assets[] | select(.name == "skidfuscator.jar") | .browser_download_url') |
| 41 | +
|
| 42 | + if [ -z "$asset_url" ]; then |
| 43 | + echo "Could not find skidfuscator.jar in the release." |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + echo "asset_url=$asset_url" >> $GITHUB_OUTPUT |
| 48 | +
|
| 49 | + - name: Download jar |
| 50 | + run: | |
| 51 | + curl -L ${{ steps.find_asset.outputs.asset_url }} -o skidfuscator.jar |
| 52 | +
|
| 53 | + - name: Compute SHA256 |
| 54 | + id: sha256 |
| 55 | + run: | |
| 56 | + SHA256=$(shasum -a 256 skidfuscator.jar | awk '{print $1}') |
| 57 | + echo "sha256=$SHA256" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Checkout tap repository |
| 60 | + uses: actions/checkout@v3 |
| 61 | + with: |
| 62 | + repository: skidfuscatordev/homebrew-skidfuscator |
| 63 | + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 64 | + ref: master |
| 65 | + - name: List Files |
| 66 | + run: ls -R |
| 67 | + - name: Cleanup and Prepare Formula |
| 68 | + run: | |
| 69 | + # Ensure Formula directory exists |
| 70 | + mkdir -p Formula |
| 71 | +
|
| 72 | + # Use absolute path and verify directory exists |
| 73 | + FORMULA_DIR="$(pwd)/Formula" |
| 74 | + FORMULA_PATH="${FORMULA_DIR}/skidfuscator.rb" |
| 75 | +
|
| 76 | + echo "Working directory: $(pwd)" |
| 77 | + echo "Formula directory: ${FORMULA_DIR}" |
| 78 | + echo "Formula path: ${FORMULA_PATH}" |
| 79 | +
|
| 80 | + # Remove any existing formula files |
| 81 | + rm -f ${FORMULA_DIR}/skidfuscator*.rb |
| 82 | +
|
| 83 | + # Create the new formula file |
| 84 | + cat > "${FORMULA_PATH}" << 'EOF' |
| 85 | + class Skidfuscator < Formula |
| 86 | + desc "A JVM-based obfuscation suite designed for Java and Android bytecode" |
| 87 | + homepage "https://github.com/skidfuscatordev/skidfuscator-java-obfuscator" |
| 88 | + url "https://github.com/skidfuscatordev/skidfuscator-java-obfuscator/releases/download/2.0.11/skidfuscator.jar" |
| 89 | + sha256 "8d5bc1f6854995495a8451417cf5235a31a56d20fc4ce6079b19963ed84c49d9" |
| 90 | + version "2.0.11" |
| 91 | + license "MIT" |
| 92 | +
|
| 93 | + def install |
| 94 | + libexec.install Dir["*.jar"] |
| 95 | + jar_name = Dir["#{libexec}/*.jar"].first |
| 96 | + (bin/"skidfuscator").write <<~EOS |
| 97 | + #!/usr/bin/env bash |
| 98 | + exec java -jar "#{jar_name}" "$@" |
| 99 | + EOS |
| 100 | + (bin/"skidfuscator").chmod 0755 |
| 101 | + end |
| 102 | +
|
| 103 | + test do |
| 104 | + output = shell_output("#{bin}/skidfuscator --help", 0) |
| 105 | + assert_match "Usage", output |
| 106 | + end |
| 107 | + end |
| 108 | + EOF |
| 109 | +
|
| 110 | + # Verify file was created |
| 111 | + ls -la ${FORMULA_DIR} |
| 112 | +
|
| 113 | + # Show file contents |
| 114 | + echo "Formula contents:" |
| 115 | + cat "${FORMULA_PATH}" |
| 116 | +
|
| 117 | + - name: Debug Formula Content |
| 118 | + run: | |
| 119 | + echo "Formula content:" |
| 120 | + cat Formula/skidfuscator.rb || echo "Failed to read formula file" |
| 121 | + echo "Git status:" |
| 122 | + git status |
| 123 | + echo "Directory contents:" |
| 124 | + ls -R |
| 125 | +
|
| 126 | + - name: Commit and push changes |
| 127 | + run: | |
| 128 | + git config user.name "github-actions" |
| 129 | + git config user.email "github-actions@github.com" |
| 130 | + git add Formula/skidfuscator.rb |
| 131 | + git commit -m "Update Skidfuscator formula to version 2.0.11" |
| 132 | + git push origin HEAD:master |
| 133 | + env: |
| 134 | + GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 135 | + |
| 136 | + |
0 commit comments