From 27706c8edb6ea87b8dff365cc7b5c3ca3bbd4f29 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 13 Feb 2026 13:10:05 -0500 Subject: [PATCH] ci: replace GH_BOT_NAME secret with var --- .github/workflows/ci-tests.yml | 6 --- .github/workflows/ci.yml | 10 +---- actions/release_homebrew/README.md | 1 + actions/release_homebrew/action.yml | 5 +++ actions/release_homebrew/ci-matrix.json | 9 +++-- actions/release_homebrew/main.py | 33 +++++++++++++++++ .../release_homebrew/test_release_homebrew.py | 37 +++++++++++++++++++ 7 files changed, 84 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 558dff9..b16b94b 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -4,12 +4,6 @@ permissions: {} on: pull_request: - branches: - - master - types: - - opened - - synchronize - - reopened push: branches: - master diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b10b973..5abb65f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,12 +4,6 @@ permissions: {} on: pull_request: - branches: - - master - types: - - opened - - synchronize - - reopened push: branches: - master @@ -75,13 +69,13 @@ jobs: - name: Process variables in with parameters id: process-with env: + ENV_GH_BOT_NAME: ${{ vars.GH_BOT_NAME }} ENV_GITHUB_EVENT_PR_NUMBER: ${{ github.event.pull_request.number }} ENV_GITHUB_EVENT_REPO_HTML_URL: ${{ github.event.repository.html_url }} ENV_GITHUB_EVENT_REPO_NAME: ${{ github.event.repository.name }} SECRETS_FACEBOOK_ACCESS_TOKEN: ${{ secrets.FACEBOOK_ACCESS_TOKEN }} SECRETS_FACEBOOK_PAGE_ID: ${{ secrets.FACEBOOK_PAGE_ID }} SECRETS_GH_BOT_EMAIL: ${{ secrets.GH_BOT_EMAIL }} - SECRETS_GH_BOT_NAME: ${{ secrets.GH_BOT_NAME }} SECRETS_GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }} SECRETS_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SECRETS_VIRUSTOTAL_API_KEY: ${{ secrets.VIRUSTOTAL_API_KEY }} @@ -97,13 +91,13 @@ jobs: -e "s|\${ github.run_id }|${GITHUB_RUN_ID}|g" \ -e "s|\${ github.workspace }|${GITHUB_WORKSPACE}|g" \ -e "s|\${ runner.os }|${RUNNER_OS}|g" \ + -e "s|\${ vars.GH_BOT_NAME }|${ENV_GH_BOT_NAME}|g" \ -e "s|\${ github.event.pull_request.number }|${ENV_GITHUB_EVENT_PR_NUMBER}|g" \ -e "s|\${ github.event.repository.html_url }|${ENV_GITHUB_EVENT_REPO_HTML_URL}|g" \ -e "s|\${ github.event.repository.name }|${ENV_GITHUB_EVENT_REPO_NAME}|g" \ -e "s|\${ secrets.FACEBOOK_ACCESS_TOKEN }|${SECRETS_FACEBOOK_ACCESS_TOKEN}|g" \ -e "s|\${ secrets.FACEBOOK_PAGE_ID }|${SECRETS_FACEBOOK_PAGE_ID}|g" \ -e "s|\${ secrets.GH_BOT_EMAIL }|${SECRETS_GH_BOT_EMAIL}|g" \ - -e "s|\${ secrets.GH_BOT_NAME }|${SECRETS_GH_BOT_NAME}|g" \ -e "s|\${ secrets.GH_BOT_TOKEN }|${SECRETS_GH_BOT_TOKEN}|g" \ -e "s|\${ secrets.GITHUB_TOKEN }|${SECRETS_GITHUB_TOKEN}|g" \ -e "s|\${ secrets.VIRUSTOTAL_API_KEY }|${SECRETS_VIRUSTOTAL_API_KEY}|g" \ diff --git a/actions/release_homebrew/README.md b/actions/release_homebrew/README.md index a589951..d81ab3a 100644 --- a/actions/release_homebrew/README.md +++ b/actions/release_homebrew/README.md @@ -34,6 +34,7 @@ steps: | Name | Description | Default | Required | |-------------------------------|-------------------------------------------------------------------------------------------|--------------------------------|----------| +| actionlint_config | Contents of actionlint config file, used to override the default brew config. | | `false` | | contribute_to_homebrew_core | Whether to contribute to homebrew-core. | `false` | `false` | | formula_file | The full path to the formula file. | | `true` | | git_email | The email to use for the commit. | | `true` | diff --git a/actions/release_homebrew/action.yml b/actions/release_homebrew/action.yml index e61e14c..008c125 100644 --- a/actions/release_homebrew/action.yml +++ b/actions/release_homebrew/action.yml @@ -8,6 +8,10 @@ branding: color: green inputs: + actionlint_config: + description: 'Contents of actionlint config file, used to override the default brew config.' + default: '' + required: false contribute_to_homebrew_core: description: 'Whether to contribute to homebrew-core.' default: 'false' @@ -164,6 +168,7 @@ runs: - name: Homebrew tests env: + INPUT_ACTIONLINT_CONFIG: ${{ inputs.actionlint_config }} INPUT_FORMULA_FILE: ${{ inputs.formula_file }} INPUT_CONTRIBUTE_TO_HOMEBREW_CORE: ${{ inputs.contribute_to_homebrew_core }} INPUT_GIT_EMAIL: ${{ inputs.git_email }} diff --git a/actions/release_homebrew/ci-matrix.json b/actions/release_homebrew/ci-matrix.json index 817556a..46b2f7d 100644 --- a/actions/release_homebrew/ci-matrix.json +++ b/actions/release_homebrew/ci-matrix.json @@ -2,10 +2,11 @@ { "runs-on": "macos-latest", "with": { + "actionlint_config": "---\n# empty config", "contribute_to_homebrew_core": true, "formula_file": "${ github.workspace }/tests/release_homebrew/Formula/hello_world.rb", "git_email": "${ secrets.GH_BOT_EMAIL }", - "git_username": "${ secrets.GH_BOT_NAME }", + "git_username": "${ vars.GH_BOT_NAME }", "org_homebrew_repo": "LizardByte/homebrew-homebrew", "org_homebrew_repo_base_branch": "master", "publish": false, @@ -16,10 +17,11 @@ { "runs-on": "ubuntu-latest", "with": { + "actionlint_config": "---\n# empty config", "contribute_to_homebrew_core": true, "formula_file": "${ github.workspace }/tests/release_homebrew/Formula/hello_world.rb", "git_email": "${ secrets.GH_BOT_EMAIL }", - "git_username": "${ secrets.GH_BOT_NAME }", + "git_username": "${ vars.GH_BOT_NAME }", "org_homebrew_repo": "LizardByte/homebrew-homebrew", "org_homebrew_repo_base_branch": "master", "publish": false, @@ -30,10 +32,11 @@ { "runs-on": "ubuntu-latest", "with": { + "actionlint_config": "---\n# empty config", "contribute_to_homebrew_core": false, "formula_file": "${ github.workspace }/tests/release_homebrew/Formula/hello_world.rb", "git_email": "${ secrets.GH_BOT_EMAIL }", - "git_username": "${ secrets.GH_BOT_NAME }", + "git_username": "${ vars.GH_BOT_NAME }", "publish": true, "remove_labels": "", "token": "${ secrets.GH_BOT_TOKEN }", diff --git a/actions/release_homebrew/main.py b/actions/release_homebrew/main.py index 3a9136a..283a6cd 100644 --- a/actions/release_homebrew/main.py +++ b/actions/release_homebrew/main.py @@ -693,6 +693,36 @@ def process_input_formula(formula_file: str) -> str: return formula +def override_actionlint_config() -> None: + """ + Override the default actionlint config file if INPUT_ACTIONLINT_CONFIG is provided. + """ + actionlint_config_content = os.getenv('INPUT_ACTIONLINT_CONFIG', '').strip() + + if not actionlint_config_content: + print('No custom actionlint config provided, using default') + return + + start_group('Overriding actionlint config') + + # Get the brew repository path + brew_repo = get_brew_repository() + actionlint_config_file = os.path.join(brew_repo, '.github', 'actionlint.yaml') + + print(f'Overriding actionlint config at: {actionlint_config_file}') + + # Create the .github directory if it doesn't exist + github_dir = os.path.dirname(actionlint_config_file) + os.makedirs(github_dir, exist_ok=True) + + # Write the custom config + with open(actionlint_config_file, 'w') as f: + f.write(actionlint_config_content) + + print('Successfully overrode actionlint config') + end_group() + + def is_brew_installed() -> bool: print('Checking if Homebrew is installed') return _run_subprocess( @@ -970,6 +1000,9 @@ def main(): print(f'::error:: Formula {formula} failed audit') FAILURES.append('audit') + # Override actionlint config if provided + override_actionlint_config() + if not brew_test_bot_only_tap_syntax(): print('::error:: brew test-bot --only-tap-syntax failed') FAILURES.append('tap-syntax') diff --git a/tests/release_homebrew/test_release_homebrew.py b/tests/release_homebrew/test_release_homebrew.py index 4340bf8..79fa985 100644 --- a/tests/release_homebrew/test_release_homebrew.py +++ b/tests/release_homebrew/test_release_homebrew.py @@ -1193,3 +1193,40 @@ def test_process_input_formula_skips_commit_for_non_git_repo(capsys, operating_s captured = capsys.readouterr() assert 'Skipping commit for' in captured.out assert '(not a git repository)' in captured.out + + +def test_override_actionlint_config_no_config(capsys, monkeypatch, operating_system): + """Test override_actionlint_config when no custom config is provided.""" + monkeypatch.setenv('INPUT_ACTIONLINT_CONFIG', '') + + main.override_actionlint_config() + + captured = capsys.readouterr() + assert 'No custom actionlint config provided, using default' in captured.out + + +def test_override_actionlint_config_with_config(capsys, monkeypatch, operating_system, tmp_path): + """Test override_actionlint_config with a custom config.""" + # Create a mock brew repository + mock_brew_repo = tmp_path / "brew_repo" + mock_brew_repo.mkdir() + + # Mock get_brew_repository to return our temp directory + with patch.object(main, 'get_brew_repository', return_value=str(mock_brew_repo)): + custom_config = 'self-hosted-runner:\n labels:\n - self-hosted' + monkeypatch.setenv('INPUT_ACTIONLINT_CONFIG', custom_config) + + main.override_actionlint_config() + + # Check that the file was created + actionlint_config_file = mock_brew_repo / '.github' / 'actionlint.yaml' + assert actionlint_config_file.exists() + + # Check the content + with open(actionlint_config_file, 'r') as f: + content = f.read() + assert content == custom_config + + captured = capsys.readouterr() + assert 'Overriding actionlint config' in captured.out + assert 'Successfully overrode actionlint config' in captured.out