|
| 1 | +name: Setup Homebrew Tap |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + create_repo: |
| 7 | + description: 'Create tap repository if it does not exist' |
| 8 | + required: true |
| 9 | + default: 'true' |
| 10 | + |
| 11 | +jobs: |
| 12 | + setup-tap: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v3 |
| 17 | + |
| 18 | + - name: Create tap repository |
| 19 | + if: ${{ github.event.inputs.create_repo == 'true' }} |
| 20 | + uses: actions/github-script@v6 |
| 21 | + with: |
| 22 | + github-token: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 23 | + script: | |
| 24 | + try { |
| 25 | + const { data } = await github.rest.repos.get({ |
| 26 | + owner: context.repo.owner, |
| 27 | + repo: 'homebrew-cpw' |
| 28 | + }); |
| 29 | + console.log('Tap repository already exists'); |
| 30 | + } catch (error) { |
| 31 | + if (error.status === 404) { |
| 32 | + console.log('Creating tap repository...'); |
| 33 | + const { data } = await github.rest.repos.createInOrg({ |
| 34 | + org: context.repo.owner, |
| 35 | + name: 'homebrew-cpw', |
| 36 | + description: 'Homebrew tap for CPW - Copy on Write file watcher', |
| 37 | + private: false, |
| 38 | + auto_init: true |
| 39 | + }); |
| 40 | + console.log('Tap repository created: ' + data.html_url); |
| 41 | + } else { |
| 42 | + console.error('Error checking repository:', error); |
| 43 | + process.exit(1); |
| 44 | + } |
| 45 | + } |
| 46 | +
|
| 47 | + - name: Setup Git |
| 48 | + run: | |
| 49 | + git config --global user.email "action@github.com" |
| 50 | + git config --global user.name "GitHub Action" |
| 51 | +
|
| 52 | + - name: Clone tap repository |
| 53 | + run: | |
| 54 | + git clone https://${{ secrets.HOMEBREW_TAP_TOKEN }}@github.com/${{ github.repository_owner }}/homebrew-cpw.git tap |
| 55 | +
|
| 56 | + - name: Create formula directory |
| 57 | + run: | |
| 58 | + mkdir -p tap/Formula |
| 59 | +
|
| 60 | + - name: Copy formula template |
| 61 | + run: | |
| 62 | + cp Formula/cpw.rb tap/Formula/ |
| 63 | +
|
| 64 | + - name: Commit and push |
| 65 | + working-directory: ./tap |
| 66 | + run: | |
| 67 | + git add Formula/cpw.rb |
| 68 | + git commit -m "Initial formula setup" || echo "No changes to commit" |
| 69 | + git push https://${{ secrets.HOMEBREW_TAP_TOKEN }}@github.com/${{ github.repository_owner }}/homebrew-cpw.git |
0 commit comments