Skip to content

Commit

Permalink
try that
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbhmr authored Nov 14, 2023
1 parent ba32534 commit dd2f422
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

</table>

🔢 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 <b>@github-actions\[bot\]</b> as the default Git author
Expand All @@ -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:
Expand All @@ -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

<!-- prettier-ignore-start -->
[safe directories]: https://git-scm.com/docs/git-config/2.35.2#Documentation/git-config.txt-safedirectory
<!-- prettier-ignore-end -->
11 changes: 9 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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!,
Expand Down Expand Up @@ -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}`;
}

0 comments on commit dd2f422

Please sign in to comment.