From 421b6f6eb41dd00dbd5217edb7274978701d30bb Mon Sep 17 00:00:00 2001 From: Vignesh Rao Date: Fri, 4 Oct 2024 18:27:28 -0500 Subject: [PATCH] Create a matrix publisher --- .github/workflows/matrix-publisher.yml | 54 ++++++++++++++++++++++++++ update-toml.py | 29 ++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/matrix-publisher.yml create mode 100644 update-toml.py diff --git a/.github/workflows/matrix-publisher.yml b/.github/workflows/matrix-publisher.yml new file mode 100644 index 00000000..d626dd78 --- /dev/null +++ b/.github/workflows/matrix-publisher.yml @@ -0,0 +1,54 @@ +name: matrix-publisher + +on: + workflow_dispatch: + inputs: + dry_run: + description: "Dry run?" + type: choice + options: + - "true" + - "false" + +jobs: + publisher: + runs-on: thevickypedia-lite + strategy: + fail-fast: false + matrix: + project_names: + - jarvis-bot + - jarvis-nlp + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set dry-run + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + echo "::notice title=DryRun::Setting dry run to ${{ inputs.dry_run }} for '${{ github.event_name }}' event" + echo "dry_run=${{ inputs.dry_run }}" >> $GITHUB_ENV + elif [[ "${{ github.event_name }}" == "push" ]]; then + echo "::notice title=DryRun::Setting dry run to true for '${{ github.event_name }}' event" + echo "dry_run=true" >> $GITHUB_ENV + else + echo "::notice title=DryRun::Setting dry run to false for '${{ github.event_name }}' event" + echo "dry_run=false" >> $GITHUB_ENV + fi + + - name: Set project name to ${{ matrix.project_names }} + run: | + python -m pip install --upgrade pip + python -m pip install toml + python update-toml.py pyproject.toml "${{ matrix.project_names }}" + shell: bash + + - name: Echo pyproject.toml + run: cat pyproject.toml + shell: bash + + - uses: thevickypedia/pypi-publisher@v3 + with: + dry-run: ${{ env.dry_run }} + token: ${{ secrets.PYPI_TOKEN }} diff --git a/update-toml.py b/update-toml.py new file mode 100644 index 00000000..d24aee7c --- /dev/null +++ b/update-toml.py @@ -0,0 +1,29 @@ +import sys + +import toml + + +def update_name_in_pyproject(file_path, new_name_value): + try: + with open(file_path, 'r') as file: + data = toml.load(file) + except FileNotFoundError: + print(f"TOML file {file_path!r} not found!") + return + + # Update the 'name' in the '[project]' section + if 'project' in data: + data['project']['name'] = new_name_value + print(f"Updated 'name' to {new_name_value!r} in [project]") + else: + print("[project] section not found in TOML file!") + return + + # Write the updated content back to the TOML file + with open(file_path, 'w') as file: + toml.dump(data, file) + file.flush() + + +if __name__ == "__main__": + update_name_in_pyproject(sys.argv[1], sys.argv[2])