From adfde6c69fc152cc6a729256754a0f635bb0be3d Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 9 Mar 2024 10:01:56 -0500 Subject: [PATCH] fix: ensure checkout paths must are under github workspace (#11) --- README.md | 6 +++--- action.yml | 12 ++++++------ action/main.py | 6 ++++-- tests/conftest.py | 2 +- tests/unit/test_main.py | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4e420a7ec0f..1917aecc6ed 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ to point to a different repository if you are not using the official Homebrew/ho ```yaml steps: - - name: Publish Homebrew Formula + - name: Validate and Publish Homebrew Formula uses: LizardByte/homebrew-release-action@master with: formula_file: "${{ github.workspace }}/hello_world.rb" @@ -36,7 +36,7 @@ It's possible to overwrite the defaults by providing additional inputs: ```yaml steps: - - name: Publish Homebrew Formula + - name: Validate and Publish Homebrew Formula uses: LizardByte/homebrew-release-action@master with: contribute_to_homebrew_core: true @@ -84,7 +84,7 @@ jobs: run: | # whatever you need to do to generate the formula - - name: Publish Homebrew Formula + - name: Validate and Publish Homebrew Formula uses: LizardByte/homebrew-release-action@master with: formula_file: "${{ github.workspace }}/build/hello_world.rb" diff --git a/action.yml b/action.yml index 52684ec28e9..d12b8f50513 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,6 @@ --- name: "Homebrew Release" -description: "A reusable action to publish a Homebrew formula to a tap." +description: "A reusable action to audit, install, test, and publish a Homebrew formula." author: "LizardByte" inputs: contribute_to_homebrew_core: @@ -97,7 +97,7 @@ runs: with: repository: ${{ inputs.org_homebrew_repo }} ref: ${{ inputs.org_homebrew_repo_branch }} - path: ${{ github.action_path }}/org_homebrew_repo + path: ${{ github.workspace }}/homebrew-release-action/org_homebrew_repo persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of the personal token fetch-depth: 1 @@ -106,7 +106,7 @@ runs: uses: actions/checkout@v4 with: repository: ${{ inputs.homebrew_core_fork_repo }} - path: ${{ github.action_path }}/homebrew_core_fork_repo + path: ${{ github.workspace }}/homebrew-release-action/homebrew_core_fork_repo persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of the personal token fetch-depth: 1 @@ -138,7 +138,7 @@ runs: author_email: ${{ inputs.git_email }} author_name: ${{ inputs.git_username }} branch: ${{ inputs.org_homebrew_repo_branch }} # commit to target branch - directory: ${{ github.action_path }}/org_homebrew_repo + directory: ${{ github.workspace }}/homebrew-release-action/org_homebrew_repo github_token: ${{ inputs.token }} message: "Update ${{ github.repository }} to ${{ github.sha }}" repository: ${{ inputs.org_homebrew_repo }} @@ -150,7 +150,7 @@ runs: author_email: ${{ inputs.git_email }} author_name: ${{ inputs.git_username }} branch: ${{ steps.homebrew-tests.outputs.homebrew_core_branch }} - directory: ${{ github.action_path }}/homebrew_core_fork_repo + directory: ${{ github.workspace }}/homebrew-release-action/homebrew_core_fork_repo force: true # need to force since the branch is sometimes reset github_token: ${{ inputs.token }} message: "Update ${{ github.repository }} to ${{ github.sha }}" @@ -161,7 +161,7 @@ runs: GH_TOKEN: ${{ inputs.token }} if: ${{ inputs.contribute_to_homebrew_core == 'true' && inputs.publish == 'true' }} shell: bash - working-directory: ${{ github.action_path }}/homebrew_core_fork_repo + working-directory: ${{ github.workspace }}/homebrew-release-action/homebrew_core_fork_repo run: | # Check if a pull request already exists with the same head branch PR_EXISTS=$(gh pr list \ diff --git a/action/main.py b/action/main.py index e770b61dffc..f298cc6b0c2 100644 --- a/action/main.py +++ b/action/main.py @@ -208,8 +208,10 @@ def process_input_formula(formula_file: str) -> str: capture_output=True ) - org_homebrew_repo = os.path.join(os.environ['GITHUB_ACTION_PATH'], 'org_homebrew_repo') - homebrew_core_fork_repo = os.path.join(os.environ['GITHUB_ACTION_PATH'], 'homebrew_core_fork_repo') + org_homebrew_repo = os.path.join( + os.environ['GITHUB_WORKSPACE'], 'homebrew-release-action', 'org_homebrew_repo') + homebrew_core_fork_repo = os.path.join( + os.environ['GITHUB_WORKSPACE'], 'homebrew-release-action', 'homebrew_core_fork_repo') print(f'org_homebrew_repo: {org_homebrew_repo}') print(f'homebrew_core_fork_repo: {homebrew_core_fork_repo}') diff --git a/tests/conftest.py b/tests/conftest.py index bd4b18a3792..e0210e4fd87 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -56,7 +56,7 @@ def operating_system(): @pytest.fixture(scope='function') # todo: fix repo deletion def homebrew_core_fork_repo(): - directory = os.environ['GITHUB_ACTION_PATH'] + directory = os.path.join(os.environ['GITHUB_WORKSPACE'], 'homebrew-release-action') os.makedirs(directory, exist_ok=True) repo = 'homebrew_core_fork_repo' diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 1955b8b1111..2accdc93ffe 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -100,8 +100,8 @@ def test_proces_input_formula(): assert formula == 'hello_world' dirs = [ - os.path.join(os.environ['GITHUB_ACTION_PATH'], 'org_homebrew_repo'), - os.path.join(os.environ['GITHUB_ACTION_PATH'], 'homebrew_core_fork_repo'), + os.path.join(os.environ['GITHUB_WORKSPACE'], 'homebrew-release-action', 'org_homebrew_repo'), + os.path.join(os.environ['GITHUB_WORKSPACE'], 'homebrew-release-action', 'homebrew_core_fork_repo'), ] for d in dirs: