From 6076c77a448c70297b2164b492c71ac9f2633f9f Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Thu, 29 Aug 2024 17:51:11 -0400 Subject: [PATCH 01/11] feat: implemented Pizza GitHub action --- README.md | 6 +- action.yml | 5 +- index.js | 69 ++----------- package-lock.json | 258 ++++++++++++++++++++++++++-------------------- package.json | 3 +- 5 files changed, 166 insertions(+), 175 deletions(-) diff --git a/README.md b/README.md index b4e7964..2df833d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ For more information about the pizza-cli. check out the OpenSauced [pizza-cli](h To use this action, you need to add the following to a GitHub Actions workflow file. The YAML snippet below uses the command to update your CODEOWNERS file in your repository, but replace it with whatever pizza-cli command you want to run. ```yaml -name: Runs the OpenSauced Pizza CLI +name: OpenSauced Pizza Action on: schedule: @@ -20,14 +20,14 @@ on: workflow_dispatch: # Allow manual triggering jobs: - update-dev-card: + pizza-action: runs-on: ubuntu-latest steps: - name: Pizza Action uses: open-sauced/pizza-action@v1.0.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} - command: "generate codeowners ./" + pizza-args: "generate codeowners ./" ``` We suggest you add this to a workflow file in the `.github/workflows` directory of your repository and call it something like `pizza-action.yml`. diff --git a/action.yml b/action.yml index ad12472..58e252a 100644 --- a/action.yml +++ b/action.yml @@ -28,13 +28,12 @@ runs: working-directory: ${{ github.action_path }} - name: Install pizza-cli - run: go install github.com/open-sauced/pizza-cli@latest + run: npm i -g pizza shell: bash - working-directory: ${{ github.action_path }} - name: Run action run: node ${{ github.action_path }}/index.js shell: bash - working-directory: ${{ github.action_path }} env: INPUT_GITHUB-TOKEN: ${{ inputs.github-token }} + INPUT_PIZZA-ARGS: ${{ inputs.pizza-args }} diff --git a/index.js b/index.js index 2af32f6..3d0d865 100644 --- a/index.js +++ b/index.js @@ -1,69 +1,20 @@ const core = require("@actions/core"); -const github = require("@actions/github"); -const fs = require("fs"); +const exec = require("@actions/exec"); async function run() { try { - const token = core.getInput("github-token"); const pizzaArgs = core.getInput("pizza-args"); + const args = pizzaArgs.split(/\s+/).filter((arg) => arg.length > 0); - // Run the pizza CLI command using the given pizza arguments - const { execSync } = require("child_process"); - execSync(`pizza ${pizzaCommand}`); + console.log("Running Pizza CLI with args:", args); + await exec.exec("pizza", args); - // Commit and push changes - const octokit = github.getOctokit(token); - const { repo, owner } = github.context.repo; - - const { data: refData } = await octokit.rest.git.getRef({ - owner, - repo, - ref: `heads/${github.context.ref.replace("refs/heads/", "")}`, - }); - - const { data: commitData } = await octokit.rest.git.getCommit({ - owner, - repo, - commit_sha: refData.object.sha, - }); - - const { data: blobData } = await octokit.rest.git.createBlob({ - owner, - repo, - content: fs.readFileSync(outputPath, { encoding: "base64" }), - encoding: "base64", - }); - - const { data: treeData } = await octokit.rest.git.createTree({ - owner, - repo, - base_tree: commitData.tree.sha, - tree: [ - { - path: outputPath, - mode: "100644", - type: "blob", - sha: blobData.sha, - }, - ], - }); - - const { data: newCommitData } = await octokit.rest.git.createCommit({ - owner, - repo, - message: `Automated pizza update for command ${pizzaCommand}`, - tree: treeData.sha, - parents: [commitData.sha], - }); - - await octokit.rest.git.updateRef({ - owner, - repo, - ref: `heads/${github.context.ref.replace("refs/heads/", "")}`, - sha: newCommitData.sha, - }); - - console.log("Changes committed and pushed successfully"); + // Add and commit changes + await exec.exec("git config --global user.name github-actions"); + await exec.exec("git config --global user.email github-actions@github.com"); + await exec.exec("git add ."); + await exec.exec('git commit -m "Auto-commit from OpenSauced Pizza Action"'); + await exec.exec("git push"); } catch (error) { core.setFailed(error.message); } diff --git a/package-lock.json b/package-lock.json index 485aa2e..f53e321 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", - "@actions/github": "^6.0.0" + "@actions/exec": "^1.1.1", + "@actions/github": "^5.1.1" } }, "node_modules/@actions/core": { @@ -22,15 +23,25 @@ "uuid": "^8.3.2" } }, + "node_modules/@actions/exec": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", + "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", + "license": "MIT", + "dependencies": { + "@actions/io": "^1.0.1" + } + }, "node_modules/@actions/github": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@actions/github/-/github-6.0.0.tgz", - "integrity": "sha512-alScpSVnYmjNEXboZjarjukQEzgCRmjMv6Xj47fsdnqGS73bjJNDpiiXmp8jr0UZLdUB6d9jW63IcmddUP+l0g==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.1.tgz", + "integrity": "sha512-Nk59rMDoJaV+mHCOJPXuvB1zIbomlKS0dmSIqPGxd0enAXBnOfn4VWF+CGtRCwXZG9Epa54tZA7VIRlJDS8A6g==", + "license": "MIT", "dependencies": { - "@actions/http-client": "^2.2.0", - "@octokit/core": "^5.0.1", - "@octokit/plugin-paginate-rest": "^9.0.0", - "@octokit/plugin-rest-endpoint-methods": "^10.0.0" + "@actions/http-client": "^2.0.1", + "@octokit/core": "^3.6.0", + "@octokit/plugin-paginate-rest": "^2.17.0", + "@octokit/plugin-rest-endpoint-methods": "^5.13.0" } }, "node_modules/@actions/http-client": { @@ -42,6 +53,12 @@ "undici": "^5.25.4" } }, + "node_modules/@actions/io": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", + "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==", + "license": "MIT" + }, "node_modules/@fastify/busboy": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", @@ -51,167 +68,172 @@ } }, "node_modules/@octokit/auth-token": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz", - "integrity": "sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==", - "engines": { - "node": ">= 18" + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.5.0.tgz", + "integrity": "sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^6.0.3" } }, "node_modules/@octokit/core": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.2.0.tgz", - "integrity": "sha512-1LFfa/qnMQvEOAdzlQymH0ulepxbxnCYAKJZfMci/5XJyIHWgEYnDmgnKakbTh7CH2tFQ5O60oYDvns4i9RAIg==", - "dependencies": { - "@octokit/auth-token": "^4.0.0", - "@octokit/graphql": "^7.1.0", - "@octokit/request": "^8.3.1", - "@octokit/request-error": "^5.1.0", - "@octokit/types": "^13.0.0", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz", + "integrity": "sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==", + "license": "MIT", + "dependencies": { + "@octokit/auth-token": "^2.4.4", + "@octokit/graphql": "^4.5.8", + "@octokit/request": "^5.6.3", + "@octokit/request-error": "^2.0.5", + "@octokit/types": "^6.0.3", "before-after-hook": "^2.2.0", "universal-user-agent": "^6.0.0" - }, - "engines": { - "node": ">= 18" } }, "node_modules/@octokit/endpoint": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.5.tgz", - "integrity": "sha512-ekqR4/+PCLkEBF6qgj8WqJfvDq65RH85OAgrtnVp1mSxaXF03u2xW/hUdweGS5654IlC0wkNYC18Z50tSYTAFw==", + "version": "6.0.12", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.12.tgz", + "integrity": "sha512-lF3puPwkQWGfkMClXb4k/eUT/nZKQfxinRWJrdZaJO85Dqwo/G0yOC434Jr2ojwafWJMYqFGFa5ms4jJUgujdA==", + "license": "MIT", "dependencies": { - "@octokit/types": "^13.1.0", + "@octokit/types": "^6.0.3", + "is-plain-object": "^5.0.0", "universal-user-agent": "^6.0.0" - }, - "engines": { - "node": ">= 18" } }, "node_modules/@octokit/graphql": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.1.0.tgz", - "integrity": "sha512-r+oZUH7aMFui1ypZnAvZmn0KSqAUgE1/tUXIWaqUCa1758ts/Jio84GZuzsvUkme98kv0WFY8//n0J1Z+vsIsQ==", + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.8.0.tgz", + "integrity": "sha512-0gv+qLSBLKF0z8TKaSKTsS39scVKF9dbMxJpj3U0vC7wjNWFuIpL/z76Qe2fiuCbDRcJSavkXsVtMS6/dtQQsg==", + "license": "MIT", "dependencies": { - "@octokit/request": "^8.3.0", - "@octokit/types": "^13.0.0", + "@octokit/request": "^5.6.0", + "@octokit/types": "^6.0.3", "universal-user-agent": "^6.0.0" - }, - "engines": { - "node": ">= 18" } }, "node_modules/@octokit/openapi-types": { - "version": "22.2.0", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-22.2.0.tgz", - "integrity": "sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==" + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==", + "license": "MIT" }, "node_modules/@octokit/plugin-paginate-rest": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-9.2.1.tgz", - "integrity": "sha512-wfGhE/TAkXZRLjksFXuDZdmGnJQHvtU/joFQdweXUgzo1XwvBCD4o4+75NtFfjfLK5IwLf9vHTfSiU3sLRYpRw==", + "version": "2.21.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.21.3.tgz", + "integrity": "sha512-aCZTEf0y2h3OLbrgKkrfFdjRL6eSOo8komneVQJnYecAxIej7Bafor2xhuDJOIFau4pk0i/P28/XgtbyPF0ZHw==", + "license": "MIT", "dependencies": { - "@octokit/types": "^12.6.0" - }, - "engines": { - "node": ">= 18" + "@octokit/types": "^6.40.0" }, "peerDependencies": { - "@octokit/core": "5" - } - }, - "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/openapi-types": { - "version": "20.0.0", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", - "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" - }, - "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/types": { - "version": "12.6.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", - "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", - "dependencies": { - "@octokit/openapi-types": "^20.0.0" + "@octokit/core": ">=2" } }, "node_modules/@octokit/plugin-rest-endpoint-methods": { - "version": "10.4.1", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-10.4.1.tgz", - "integrity": "sha512-xV1b+ceKV9KytQe3zCVqjg+8GTGfDYwaT1ATU5isiUyVtlVAO3HNdzpS4sr4GBx4hxQ46s7ITtZrAsxG22+rVg==", + "version": "5.16.2", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.16.2.tgz", + "integrity": "sha512-8QFz29Fg5jDuTPXVtey05BLm7OB+M8fnvE64RNegzX7U+5NUXcOcnpTIK0YfSHBg8gYd0oxIq3IZTe9SfPZiRw==", + "license": "MIT", "dependencies": { - "@octokit/types": "^12.6.0" - }, - "engines": { - "node": ">= 18" + "@octokit/types": "^6.39.0", + "deprecation": "^2.3.1" }, "peerDependencies": { - "@octokit/core": "5" - } - }, - "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/openapi-types": { - "version": "20.0.0", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", - "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" - }, - "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/types": { - "version": "12.6.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", - "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", - "dependencies": { - "@octokit/openapi-types": "^20.0.0" + "@octokit/core": ">=3" } }, "node_modules/@octokit/request": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.4.0.tgz", - "integrity": "sha512-9Bb014e+m2TgBeEJGEbdplMVWwPmL1FPtggHQRkV+WVsMggPtEkLKPlcVYm/o8xKLkpJ7B+6N8WfQMtDLX2Dpw==", + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz", + "integrity": "sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==", + "license": "MIT", "dependencies": { - "@octokit/endpoint": "^9.0.1", - "@octokit/request-error": "^5.1.0", - "@octokit/types": "^13.1.0", + "@octokit/endpoint": "^6.0.1", + "@octokit/request-error": "^2.1.0", + "@octokit/types": "^6.16.1", + "is-plain-object": "^5.0.0", + "node-fetch": "^2.6.7", "universal-user-agent": "^6.0.0" - }, - "engines": { - "node": ">= 18" } }, "node_modules/@octokit/request-error": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.1.0.tgz", - "integrity": "sha512-GETXfE05J0+7H2STzekpKObFe765O5dlAKUTLNGeH+x47z7JjXHfsHKo5z21D/o/IOZTUEI6nyWyR+bZVP/n5Q==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz", + "integrity": "sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==", + "license": "MIT", "dependencies": { - "@octokit/types": "^13.1.0", + "@octokit/types": "^6.0.3", "deprecation": "^2.0.0", "once": "^1.4.0" - }, - "engines": { - "node": ">= 18" } }, "node_modules/@octokit/types": { - "version": "13.5.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.5.0.tgz", - "integrity": "sha512-HdqWTf5Z3qwDVlzCrP8UJquMwunpDiMPt5er+QjGzL4hqr/vBVY/MauQgS1xWxCDT1oMx1EULyqxncdCY/NVSQ==", + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "license": "MIT", "dependencies": { - "@octokit/openapi-types": "^22.2.0" + "@octokit/openapi-types": "^12.11.0" } }, "node_modules/before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", - "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==" + "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", + "license": "Apache-2.0" }, "node_modules/deprecation": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", - "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==", + "license": "ISC" + }, + "node_modules/is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", "dependencies": { "wrappy": "1" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, "node_modules/tunnel": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", @@ -234,7 +256,8 @@ "node_modules/universal-user-agent": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.1.tgz", - "integrity": "sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==" + "integrity": "sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==", + "license": "ISC" }, "node_modules/uuid": { "version": "8.3.2", @@ -244,10 +267,27 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" } } } diff --git a/package.json b/package.json index 6d1cd41..d4d31fc 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", - "@actions/github": "^6.0.0" + "@actions/exec": "^1.1.1", + "@actions/github": "^5.1.1" } } From d289cc7985096afec97912dba253d31efe2576ca Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Thu, 29 Aug 2024 19:19:21 -0400 Subject: [PATCH 02/11] stripping quotes from args from env vars --- index.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 3d0d865..8c53fb4 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,26 @@ const core = require("@actions/core"); const exec = require("@actions/exec"); +function parseArgs(input) { + const regex = /[^\s"']+|"([^"]*)"|'([^']*)'/g; + let args = []; + let match; + + while ((match = regex.exec(input))) { + if (match[1]) args.push(match[1]); // Quoted with " + else if (match[2]) args.push(match[2]); // Quoted with ' + else args.push(match[0]); // Unquoted + } + + return args; +} + async function run() { try { - const pizzaArgs = core.getInput("pizza-args"); - const args = pizzaArgs.split(/\s+/).filter((arg) => arg.length > 0); + const pizzaArgs = parseArgs(core.getInput("pizza-args") ?? ""); - console.log("Running Pizza CLI with args:", args); - await exec.exec("pizza", args); + console.log("Running Pizza CLI with args:", pizzaArgs); + await exec.exec("pizza", pizzaArgs); // Add and commit changes await exec.exec("git config --global user.name github-actions"); From 728588afa648c5e28b7a81566db9491efbbba36a Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Thu, 29 Aug 2024 19:22:03 -0400 Subject: [PATCH 03/11] stripped quotes from args and bash script on the fly --- index.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 8c53fb4..5c5865b 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,17 @@ const core = require("@actions/core"); const exec = require("@actions/exec"); +const fs = require("fs").promises; +const path = require("path"); -function parseArgs(input) { +function stripQuotes(input) { const regex = /[^\s"']+|"([^"]*)"|'([^']*)'/g; let args = []; let match; while ((match = regex.exec(input))) { - if (match[1]) args.push(match[1]); // Quoted with " - else if (match[2]) args.push(match[2]); // Quoted with ' - else args.push(match[0]); // Unquoted + if (match[1]) args.push(match[1]); // Was quoted with " + else if (match[2]) args.push(match[2]); // Was quoted with ' + else args.push(match[0]); // Was not quoted } return args; @@ -17,10 +19,29 @@ function parseArgs(input) { async function run() { try { - const pizzaArgs = parseArgs(core.getInput("pizza-args") ?? ""); + const pizzaArgs = core.getInput("pizza-args"); + console.log("Raw pizza-args:", pizzaArgs); - console.log("Running Pizza CLI with args:", pizzaArgs); - await exec.exec("pizza", pizzaArgs); + const args = stripQuotes(pizzaArgs); + console.log("Stripped args:", args); + + // Create a temporary bash script + const scriptContent = `#!/bin/bash +set -e +pizza ${args.join(" ")} +`; + console.log("Bash script content:", scriptContent); + + const scriptPath = path.join(process.cwd(), "run_pizza.sh"); + await fs.writeFile(scriptPath, scriptContent); + await fs.chmod(scriptPath, "0755"); // Make the script executable + + // Execute the bash script + console.log("Executing bash script..."); + await exec.exec(`bash ${scriptPath}`); + + // Remove the temporary script + await fs.unlink(scriptPath); // Add and commit changes await exec.exec("git config --global user.name github-actions"); @@ -29,6 +50,7 @@ async function run() { await exec.exec('git commit -m "Auto-commit from OpenSauced Pizza Action"'); await exec.exec("git push"); } catch (error) { + console.error("Error:", error); core.setFailed(error.message); } } From 418f4d7c2d6b8ea948bc4d83022f46bc50b67ef1 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 30 Aug 2024 15:23:30 -0400 Subject: [PATCH 04/11] chore: removed unnecessary JS files --- index.js | 58 --------- package-lock.json | 293 ---------------------------------------------- package.json | 22 ---- 3 files changed, 373 deletions(-) delete mode 100644 index.js delete mode 100644 package-lock.json delete mode 100644 package.json diff --git a/index.js b/index.js deleted file mode 100644 index 5c5865b..0000000 --- a/index.js +++ /dev/null @@ -1,58 +0,0 @@ -const core = require("@actions/core"); -const exec = require("@actions/exec"); -const fs = require("fs").promises; -const path = require("path"); - -function stripQuotes(input) { - const regex = /[^\s"']+|"([^"]*)"|'([^']*)'/g; - let args = []; - let match; - - while ((match = regex.exec(input))) { - if (match[1]) args.push(match[1]); // Was quoted with " - else if (match[2]) args.push(match[2]); // Was quoted with ' - else args.push(match[0]); // Was not quoted - } - - return args; -} - -async function run() { - try { - const pizzaArgs = core.getInput("pizza-args"); - console.log("Raw pizza-args:", pizzaArgs); - - const args = stripQuotes(pizzaArgs); - console.log("Stripped args:", args); - - // Create a temporary bash script - const scriptContent = `#!/bin/bash -set -e -pizza ${args.join(" ")} -`; - console.log("Bash script content:", scriptContent); - - const scriptPath = path.join(process.cwd(), "run_pizza.sh"); - await fs.writeFile(scriptPath, scriptContent); - await fs.chmod(scriptPath, "0755"); // Make the script executable - - // Execute the bash script - console.log("Executing bash script..."); - await exec.exec(`bash ${scriptPath}`); - - // Remove the temporary script - await fs.unlink(scriptPath); - - // Add and commit changes - await exec.exec("git config --global user.name github-actions"); - await exec.exec("git config --global user.email github-actions@github.com"); - await exec.exec("git add ."); - await exec.exec('git commit -m "Auto-commit from OpenSauced Pizza Action"'); - await exec.exec("git push"); - } catch (error) { - console.error("Error:", error); - core.setFailed(error.message); - } -} - -run(); diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index f53e321..0000000 --- a/package-lock.json +++ /dev/null @@ -1,293 +0,0 @@ -{ - "name": "pizza-action", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "pizza-action", - "version": "1.0.0", - "license": "MIT", - "dependencies": { - "@actions/core": "^1.10.0", - "@actions/exec": "^1.1.1", - "@actions/github": "^5.1.1" - } - }, - "node_modules/@actions/core": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz", - "integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==", - "dependencies": { - "@actions/http-client": "^2.0.1", - "uuid": "^8.3.2" - } - }, - "node_modules/@actions/exec": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", - "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", - "license": "MIT", - "dependencies": { - "@actions/io": "^1.0.1" - } - }, - "node_modules/@actions/github": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.1.tgz", - "integrity": "sha512-Nk59rMDoJaV+mHCOJPXuvB1zIbomlKS0dmSIqPGxd0enAXBnOfn4VWF+CGtRCwXZG9Epa54tZA7VIRlJDS8A6g==", - "license": "MIT", - "dependencies": { - "@actions/http-client": "^2.0.1", - "@octokit/core": "^3.6.0", - "@octokit/plugin-paginate-rest": "^2.17.0", - "@octokit/plugin-rest-endpoint-methods": "^5.13.0" - } - }, - "node_modules/@actions/http-client": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.2.tgz", - "integrity": "sha512-2TvX5LskKQzDDQI+bobIDGAjkn0NJiQlg4MTrKnZ8HfQ7nDEUbtJ1ytxPDb2bfk3Hr2XD99X8oAJISAmIoiSAQ==", - "dependencies": { - "tunnel": "^0.0.6", - "undici": "^5.25.4" - } - }, - "node_modules/@actions/io": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", - "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==", - "license": "MIT" - }, - "node_modules/@fastify/busboy": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", - "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", - "engines": { - "node": ">=14" - } - }, - "node_modules/@octokit/auth-token": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.5.0.tgz", - "integrity": "sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==", - "license": "MIT", - "dependencies": { - "@octokit/types": "^6.0.3" - } - }, - "node_modules/@octokit/core": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz", - "integrity": "sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==", - "license": "MIT", - "dependencies": { - "@octokit/auth-token": "^2.4.4", - "@octokit/graphql": "^4.5.8", - "@octokit/request": "^5.6.3", - "@octokit/request-error": "^2.0.5", - "@octokit/types": "^6.0.3", - "before-after-hook": "^2.2.0", - "universal-user-agent": "^6.0.0" - } - }, - "node_modules/@octokit/endpoint": { - "version": "6.0.12", - "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.12.tgz", - "integrity": "sha512-lF3puPwkQWGfkMClXb4k/eUT/nZKQfxinRWJrdZaJO85Dqwo/G0yOC434Jr2ojwafWJMYqFGFa5ms4jJUgujdA==", - "license": "MIT", - "dependencies": { - "@octokit/types": "^6.0.3", - "is-plain-object": "^5.0.0", - "universal-user-agent": "^6.0.0" - } - }, - "node_modules/@octokit/graphql": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.8.0.tgz", - "integrity": "sha512-0gv+qLSBLKF0z8TKaSKTsS39scVKF9dbMxJpj3U0vC7wjNWFuIpL/z76Qe2fiuCbDRcJSavkXsVtMS6/dtQQsg==", - "license": "MIT", - "dependencies": { - "@octokit/request": "^5.6.0", - "@octokit/types": "^6.0.3", - "universal-user-agent": "^6.0.0" - } - }, - "node_modules/@octokit/openapi-types": { - "version": "12.11.0", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", - "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==", - "license": "MIT" - }, - "node_modules/@octokit/plugin-paginate-rest": { - "version": "2.21.3", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.21.3.tgz", - "integrity": "sha512-aCZTEf0y2h3OLbrgKkrfFdjRL6eSOo8komneVQJnYecAxIej7Bafor2xhuDJOIFau4pk0i/P28/XgtbyPF0ZHw==", - "license": "MIT", - "dependencies": { - "@octokit/types": "^6.40.0" - }, - "peerDependencies": { - "@octokit/core": ">=2" - } - }, - "node_modules/@octokit/plugin-rest-endpoint-methods": { - "version": "5.16.2", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.16.2.tgz", - "integrity": "sha512-8QFz29Fg5jDuTPXVtey05BLm7OB+M8fnvE64RNegzX7U+5NUXcOcnpTIK0YfSHBg8gYd0oxIq3IZTe9SfPZiRw==", - "license": "MIT", - "dependencies": { - "@octokit/types": "^6.39.0", - "deprecation": "^2.3.1" - }, - "peerDependencies": { - "@octokit/core": ">=3" - } - }, - "node_modules/@octokit/request": { - "version": "5.6.3", - "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz", - "integrity": "sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==", - "license": "MIT", - "dependencies": { - "@octokit/endpoint": "^6.0.1", - "@octokit/request-error": "^2.1.0", - "@octokit/types": "^6.16.1", - "is-plain-object": "^5.0.0", - "node-fetch": "^2.6.7", - "universal-user-agent": "^6.0.0" - } - }, - "node_modules/@octokit/request-error": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz", - "integrity": "sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==", - "license": "MIT", - "dependencies": { - "@octokit/types": "^6.0.3", - "deprecation": "^2.0.0", - "once": "^1.4.0" - } - }, - "node_modules/@octokit/types": { - "version": "6.41.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", - "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", - "license": "MIT", - "dependencies": { - "@octokit/openapi-types": "^12.11.0" - } - }, - "node_modules/before-after-hook": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", - "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", - "license": "Apache-2.0" - }, - "node_modules/deprecation": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", - "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==", - "license": "ISC" - }, - "node_modules/is-plain-object": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", - "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/node-fetch": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", - "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", - "license": "MIT", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "license": "MIT" - }, - "node_modules/tunnel": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", - "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", - "engines": { - "node": ">=0.6.11 <=0.7.0 || >=0.7.3" - } - }, - "node_modules/undici": { - "version": "5.28.4", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", - "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", - "dependencies": { - "@fastify/busboy": "^2.0.0" - }, - "engines": { - "node": ">=14.0" - } - }, - "node_modules/universal-user-agent": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.1.tgz", - "integrity": "sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==", - "license": "ISC" - }, - "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "license": "BSD-2-Clause" - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "license": "MIT", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "license": "ISC" - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index d4d31fc..0000000 --- a/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "pizza-action", - "version": "1.0.0", - "description": "GitHub Action to run OpenSauced's Pizza CLI's various commands", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [ - "github", - "action", - "codeowners", - "open-sauced" - ], - "author": "Nick Taylor", - "license": "MIT", - "dependencies": { - "@actions/core": "^1.10.0", - "@actions/exec": "^1.1.1", - "@actions/github": "^5.1.1" - } -} From 01f3b4742e2b32ce761bf8edc576534dd4eda630 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 30 Aug 2024 15:27:41 -0400 Subject: [PATCH 05/11] added a commit and push script that optionally runs (false by default) --- action.yml | 39 ++++++++++++++++++++++++++------------- commit-and-push.sh | 5 +++++ 2 files changed, 31 insertions(+), 13 deletions(-) create mode 100755 commit-and-push.sh diff --git a/action.yml b/action.yml index 58e252a..ad38db2 100644 --- a/action.yml +++ b/action.yml @@ -11,29 +11,42 @@ inputs: description: "OpenSauced Pizza CLI command to run" default: "generate codeowners ./" required: true + commit-and-push: + description: "Commit and push changes" + default: "false" + required: false + runs: using: "composite" steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Setup Node - uses: actions/setup-node@v3 + - name: Setup Go + uses: actions/setup-go@v4 with: - node-version: "20" + go-version: "1.22.5" + + - name: Install pizza CLI + run: | + go install github.com/open-sauced/pizza-cli@beta + shell: bash - - name: Install dependencies - run: npm ci + - name: Check pizza CLI version + run: pizza-cli version shell: bash - working-directory: ${{ github.action_path }} - - name: Install pizza-cli - run: npm i -g pizza + - name: Run pizza CLI command + run: | + pwd + ls -la + pizza-cli ${{ inputs.pizza-args }} shell: bash + working-directory: ${{ github.workspace }} - - name: Run action - run: node ${{ github.action_path }}/index.js + - name: Commit and push changes + if: ${{ inputs.commit-and-push == 'true' }} + run: ./commit-and-push.sh shell: bash - env: - INPUT_GITHUB-TOKEN: ${{ inputs.github-token }} - INPUT_PIZZA-ARGS: ${{ inputs.pizza-args }} diff --git a/commit-and-push.sh b/commit-and-push.sh new file mode 100755 index 0000000..10a64be --- /dev/null +++ b/commit-and-push.sh @@ -0,0 +1,5 @@ +git config --global user.name github-actions +git config --global user.email github-actions@github.com +git add . +git commit -m "Auto-commit from OpenSauced Pizza Action" +git push From 5509303649f2bc6f0e273f083b1c5d1ee2aea71e Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 30 Aug 2024 15:36:48 -0400 Subject: [PATCH 06/11] added a commit and push script that optionally runs (false by default) --- README.md | 3 +-- action.yml | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2df833d..377d086 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,7 @@ jobs: - name: Pizza Action uses: open-sauced/pizza-action@v1.0.0 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - pizza-args: "generate codeowners ./" + commit-and-push: "true" ``` We suggest you add this to a workflow file in the `.github/workflows` directory of your repository and call it something like `pizza-action.yml`. diff --git a/action.yml b/action.yml index ad38db2..bdce830 100644 --- a/action.yml +++ b/action.yml @@ -4,9 +4,6 @@ branding: icon: "image" color: "orange" inputs: - github-token: - description: "GitHub token" - required: true pizza-args: description: "OpenSauced Pizza CLI command to run" default: "generate codeowners ./" @@ -50,3 +47,4 @@ runs: if: ${{ inputs.commit-and-push == 'true' }} run: ./commit-and-push.sh shell: bash + working-directory: ${{ github.workspace }} From 4f1b094431ee6b2253958ddeb276abee21440f6a Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 30 Aug 2024 15:41:25 -0400 Subject: [PATCH 07/11] removed bash script and inline git commit/push logic into action.yml --- action.yml | 7 ++++++- commit-and-push.sh | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) delete mode 100755 commit-and-push.sh diff --git a/action.yml b/action.yml index bdce830..7d04fd8 100644 --- a/action.yml +++ b/action.yml @@ -45,6 +45,11 @@ runs: - name: Commit and push changes if: ${{ inputs.commit-and-push == 'true' }} - run: ./commit-and-push.sh + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git add . + git commit -m "Auto-commit from GitHub Actions" + git push shell: bash working-directory: ${{ github.workspace }} diff --git a/commit-and-push.sh b/commit-and-push.sh deleted file mode 100755 index 10a64be..0000000 --- a/commit-and-push.sh +++ /dev/null @@ -1,5 +0,0 @@ -git config --global user.name github-actions -git config --global user.email github-actions@github.com -git add . -git commit -m "Auto-commit from OpenSauced Pizza Action" -git push From ea91dc56dcac5a6fcab09c88b1b594d54bebb1a2 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 30 Aug 2024 15:52:24 -0400 Subject: [PATCH 08/11] chore: added a comment about commit and push being optional --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 377d086..fae3f9b 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ jobs: - name: Pizza Action uses: open-sauced/pizza-action@v1.0.0 with: + # optional and false by default commit-and-push: "true" ``` From 9aeb53a27284539c9a89b441d4e434cbfa9b20b9 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 30 Aug 2024 15:55:50 -0400 Subject: [PATCH 09/11] docs: added some docs around the GitHub action inputs --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fae3f9b..301d2a2 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,14 @@ jobs: We suggest you add this to a workflow file in the `.github/workflows` directory of your repository and call it something like `pizza-action.yml`. -Depending on the pizza-cli command you run, different things will update. For example, if you run `pizza generate codeowners ./`, it will update the CODEOWNERS file in the root of your repository. +Depending on the pizza CLI command you run, different things will update. For example, if you run `pizza generate codeowners ./`, it will update the CODEOWNERS file in the root of your repository. + +## Inputs + +### `pizza-args` + +Arguments to pass to the pizza CLI. Default is `generate codeowners ./`. + +### `commit-and-push` + +Whether to commit and push the changes made by the pizza-cli. Default is `false`. From 8edcda3a986deda8edc71e46c4753ebcb5427e21 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 30 Aug 2024 15:58:38 -0400 Subject: [PATCH 10/11] chore: updated GitHub marketplace icon --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7d04fd8..62136e7 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,7 @@ name: "OpenSauced Pizza Action" description: "GitHub Action to run OpenSauced's Pizza CLI's various commands" branding: - icon: "image" + icon: "package" color: "orange" inputs: pizza-args: From bc73099b46a95cde360b20ffa87939a6bc4a9f1d Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Fri, 30 Aug 2024 16:05:23 -0400 Subject: [PATCH 11/11] docs: added some docs around fetch depth 0 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 301d2a2..ad9600a 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ We suggest you add this to a workflow file in the `.github/workflows` directory Depending on the pizza CLI command you run, different things will update. For example, if you run `pizza generate codeowners ./`, it will update the CODEOWNERS file in the root of your repository. +The pizza CLI's "generate codeowners ./" command requires a full repository history to accurately determine code ownership over time. Fetch-depth is set to 0 in this action to ensure all historical commits are available, allowing the command to analyze the entire project timeline and produce a comprehensive CODEOWNERS file. + ## Inputs ### `pizza-args`