-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented Pizza GitHub action
- Loading branch information
1 parent
0528b27
commit 6076c77
Showing
5 changed files
with
166 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected] | ||
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`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected]"); | ||
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); | ||
} | ||
|
Oops, something went wrong.