From 78af16c89b9f531769ccfdee63654c1313ac7a8a Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:38:32 -0500 Subject: [PATCH] feat: initial version --- .github/workflows/ci.yml | 56 ++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ LICENSE | 21 ++++++++++++++ README.md | 47 ++++++++++++++++++++++++++++-- action.yml | 47 ++++++++++++++++++++++++++++++ tests/Formula/hello_world.rb | 21 ++++++++++++++ 6 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 action.yml create mode 100644 tests/Formula/hello_world.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..be45764a203 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +--- +name: CI + +on: + pull_request: + branches: [master] + types: [opened, synchronize, reopened] + push: + branches: [master] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + action: + environment: + ${{ github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name != github.repository && + 'external' || 'internal' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Release + id: setup_release + uses: LizardByte/setup-release-action@v2024.202.205234 + with: + fail_on_events_api_error: # PRs will fail if this is true + ${{ github.event_name == 'pull_request' && 'false' || 'true' }} + github_token: ${{ secrets.GITHUB_TOKEN }} # can use GITHUB_TOKEN for read-only access + + - name: Run Action + id: action + uses: ./ + with: + git_email: ${{ secrets.GH_BOT_EMAIL }} + git_username: ${{ secrets.GH_BOT_NAME }} + src_root: ${{ github.workspace }}/tests + target_repo: ${{ github.repository }}:tests + token: ${{ secrets.GH_BOT_TOKEN }} + + - name: Create/Update GitHub Release + if: ${{ steps.setup_release.outputs.publish_release == 'true' }} + uses: LizardByte/create-release-action@v2023.1219.224026 + with: + allowUpdates: true + body: '' + discussionCategory: announcements + generateReleaseNotes: true + name: ${{ steps.setup_release.outputs.release_tag }} + prerelease: ${{ steps.setup_release.outputs.publish_pre_release }} + tag: ${{ steps.setup_release.outputs.release_tag }} + token: ${{ secrets.GH_BOT_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..225ce7e57c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# ignore jetbrains files +.idea/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000000..9d37d76f848 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 LizardByte + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index fd3e658ce52..4e24665d0e4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,45 @@ -# template-base -Base repository template for LizardByte. +# homebrew-release-action +[![GitHub Workflow Status (CI)](https://img.shields.io/github/actions/workflow/status/lizardbyte/homebrew-release-action/ci.yml.svg?branch=master&label=CI%20build&logo=github&style=for-the-badge)](https://github.com/LizardByte/homebrew-release-action/actions/workflows/ci.yml?query=branch%3Amaster) + +A reusable action to publish homebrew formulas to a tap. +This action is tailored to the @LizardByte organization, but can be used by anyone if they follow the same conventions. + +This is basically a wrapper around [adrianjost/files-sync-action](https://github.com/adrianjost/files-sync-action), +with some different defaults to make it easier to use within the @LizardByte organization. + +## Basic Usage + +See [action.yml](action.yml) + +The intent here is that the formulas are build in the upstream repository, instead of the tap repository. + +As part of an automated release workflow, this action can be used to upload the built formulas to the tap repository. + +```yaml +steps: + - name: Publish Homebrew Formula + uses: LizardByte/homebrew-release-action@master + with: + git_email: ${{ secrets.GIT_EMAIL }} + git_username: ${{ secrets.GIT_USERNAME }} + target_repo: repo_owner/repo_name + token: ${{ secrets.PAT }} +``` + +It's possible to overwrite the defaults by providing additional inputs: + +```yaml +steps: + - name: Publish Homebrew Formula + uses: LizardByte/homebrew-release-action@master + with: + file_patterns: | + ^Aliases/* + ^Formula/* + git_email: ${{ secrets.GIT_EMAIL }} + git_username: ${{ secrets.GIT_USERNAME }} + skip_delete: true + src_root: ${{ github.workspace }}/build + target_repo: repo_owner/repo_name + token: ${{ secrets.PAT }} +``` diff --git a/action.yml b/action.yml new file mode 100644 index 00000000000..d6a3787cc11 --- /dev/null +++ b/action.yml @@ -0,0 +1,47 @@ +--- +name: "Homebrew Release" +description: "A reusable action to publish a Homebrew formula to a tap." +author: "LizardByte" +inputs: + file_patterns: + description: 'The file patterns to publish.' + default: '^Formula/*' + required: true + git_email: + description: 'The email to use for the commit.' + required: true + git_username: + description: 'The username to use for the commit.' + required: true + skip_delete: + description: 'Skip deleting formulas in the target repo, that do not exist in the source repo.' + default: 'false' + required: false + src_root: + description: 'Prepend this to the file patterns.' + default: '/' + required: false + target_repo: + description: 'The target repository to publish to.' + default: 'LizardByte/homebrew' + required: false + token: + description: 'Github Token.' + required: true + +runs: + using: "composite" + steps: + - name: Homebrew Release + if: >- + github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: adrianjost/files-sync-action@v2.1.0 + with: + COMMIT_MESSAGE: "Update ${{ github.repository }} to ${{ github.sha }}" + FILE_PATTERNS: ${{ inputs.file_patterns }} + GIT_EMAIL: ${{ inputs.git_email }} + GIT_USERNAME: ${{ inputs.git_username }} + GITHUB_TOKEN: ${{ inputs.token }} + SKIP_DELETE: ${{ inputs.skip_delete }} + SRC_ROOT: ${{ inputs.src_root }} + TARGET_REPOS: ${{ inputs.target_repo }} diff --git a/tests/Formula/hello_world.rb b/tests/Formula/hello_world.rb new file mode 100644 index 00000000000..3f0e1a79629 --- /dev/null +++ b/tests/Formula/hello_world.rb @@ -0,0 +1,21 @@ +class HelloWorld < Formula + desc "Simple program that outputs 'Hello, World!'" + homepage "https://app.lizardbyte.devm" + url "https://github.com/LizardByte/homebrew-release-action.git" + version "0.0.1" + + def install + # create hello world sh file with echo command + (buildpath/"hello-world").write <<~EOS + #!/bin/sh + echo "Hello, World!" + EOS + + # install the hello-world file to the bin directory + bin.install "hello-world" + end + + test do + system "#{bin}/hello-world" + end +end