diff --git a/README.md b/README.md index 2023f12..96d393a 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,6 @@ -🔢 Lets you pick a specific version of Git to use (if needed) \ -⚡ Defaults to using the system version of Git \ 📂 Lets you add additional [safe directories] \ 🔑 Configures Git to use `github.token` when pushing/pulling from `github.server_url` \ 👤 Sets up @github-actions\[bot\] as the default Git author @@ -32,6 +30,8 @@ ![GitHub Actions](https://img.shields.io/static/v1?style=for-the-badge&message=GitHub+Actions&color=2088FF&logo=GitHub+Actions&logoColor=FFFFFF&label=) +**🚀 Here's what you want:** + ```yml on: push jobs: @@ -45,3 +45,13 @@ jobs: - run: git commit --message 'Prettier' # ✅ - run: git push # ✅ ``` + +### Inputs + +⚠️ Support for choosing a `git-version` is not yet implemented. Contributions are welcome! ❤️ + +### Outputs + + +[safe directories]: https://git-scm.com/docs/git-config/2.35.2#Documentation/git-config.txt-safedirectory + diff --git a/action.yml b/action.yml index 37ab8ae..1064642 100644 --- a/action.yml +++ b/action.yml @@ -6,13 +6,20 @@ branding: color: orange inputs: - token: + github-token: default: ${{ github.token }} - git-version: {} + github-server-url: + default: ${{ github.server_url }} + # gitlab-token: {} + # gitlab-server-url: {} + # bitbucket-token: {} + # bitbucket-server-url: {} user: default: github-actions[bot] user-name: {} user-email: {} + safe-directory: + default: . runs: using: node20 diff --git a/src/main.ts b/src/main.ts index 40c2f5f..ba68a52 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,8 @@ +import assert from "node:assert/strict"; import { $ } from "execa"; import * as core from "@actions/core"; -import assert from "node:assert/strict"; +import * as tc from "@actions/tool-cache"; +import { glob } from "glob"; const githubContext = { actor: process.env.GITHUB_ACTOR!, @@ -47,17 +49,24 @@ function getNameEmailInput( return [name, email]; } -const version = core.getInput("git-version"); - +const githubToken = core.getInput("github-token"); +const githubServerURL = core.getInput("github-server-url"); const [userName, userEmail] = getNameEmailInput("user"); +const safeDirectoryGlobs = core.getMultilineInput("safe-directory"); +const safeDirectories = await glob(safeDirectoryGlobs); if (userName && userEmail) { await $({ stdio: "inherit" })`git config --global user.name ${userName}`; await $({ stdio: "inherit" })`git config --global user.email ${userEmail}`; } -const prefix = new URL(githubContext.server_url).origin + "/"; -const githubToken = core.getInput("token"); +const prefix = new URL(githubServerURL).origin + "/"; await $({ stdio: "inherit", })`git config --global http.${prefix}.extraheader ${`AUTHORIZATION: basic ${githubToken}`}`; + +for (const safeDirectory of safeDirectories) { + await $({ + stdio: "inherit", + })`git config --global --add safe.directory ${safeDirectory}`; +}