From 29634c084c3bb09f74a13a6235ac89bb6a2e1ae0 Mon Sep 17 00:00:00 2001 From: Pratham Dubey <134331217+prathamdby@users.noreply.github.com> Date: Sun, 17 Mar 2024 18:05:52 +0530 Subject: [PATCH 1/3] Implement a GitHub workflow to automatically run add_license.py --- .github/workflows/add-license.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/add-license.yml diff --git a/.github/workflows/add-license.yml b/.github/workflows/add-license.yml new file mode 100644 index 0000000..adb70ce --- /dev/null +++ b/.github/workflows/add-license.yml @@ -0,0 +1,24 @@ +name: Add License + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + + add-license: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Add License + run: | + python scripts/add_license.py From fc3a8977434995a0fc7881b2fb431036760a0db2 Mon Sep 17 00:00:00 2001 From: Pratham Dubey <134331217+prathamdby@users.noreply.github.com> Date: Sun, 17 Mar 2024 18:14:14 +0530 Subject: [PATCH 2/3] Update the Add License workflow to commit any changes --- .github/workflows/add-license.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/add-license.yml b/.github/workflows/add-license.yml index adb70ce..b658065 100644 --- a/.github/workflows/add-license.yml +++ b/.github/workflows/add-license.yml @@ -13,12 +13,32 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required to retrieve full commit history - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.12' + python-version: "3.12" - name: Add License run: | python scripts/add_license.py + + - name: Check for file changes + id: changes + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "::set-output name=changes::true" + else + echo "::set-output name=changes::false" + fi + + - name: Commit changes + if: steps.changes.outputs.changes == "true" + run: | + git config --global user.name "GitHub Actions Bot" + git config --global user.email "actions@github.com" + git add . + git commit -m "Add license to files" + git push From b09433d6ddcd836a234aafd17fb2a3a1689a30d0 Mon Sep 17 00:00:00 2001 From: Pratham Dubey <134331217+prathamdby@users.noreply.github.com> Date: Sun, 17 Mar 2024 18:16:56 +0530 Subject: [PATCH 3/3] Fix the derp in the Add License workflow --- .github/workflows/add-license.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-license.yml b/.github/workflows/add-license.yml index b658065..cabb406 100644 --- a/.github/workflows/add-license.yml +++ b/.github/workflows/add-license.yml @@ -35,7 +35,7 @@ jobs: fi - name: Commit changes - if: steps.changes.outputs.changes == "true" + if: steps.changes.outputs.changes == true run: | git config --global user.name "GitHub Actions Bot" git config --global user.email "actions@github.com"