Skip to content

Commit 20cd8bc

Browse files
committedSep 14, 2019
Initial commit
0 parents  commit 20cd8bc

File tree

9 files changed

+292
-0
lines changed

9 files changed

+292
-0
lines changed
 

‎.github/workflows/checkin.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: "PR Checks"
2+
on: [pull_request, push]
3+
4+
jobs:
5+
check_pr:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v1
9+
10+
- name: "npm ci"
11+
run: npm ci
12+
13+
- name: "npm run build"
14+
run: npm run build
15+
16+
- name: "check for uncommitted changes"
17+
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
18+
run: |
19+
git diff --exit-code --stat -- . ':!node_modules' \
20+
|| (echo "##[error] found changed files after build. please 'npm run build && npm run format'" \
21+
"and check in all changes" \
22+
&& exit 1)

‎.gitignore

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
__tests__/runner/*
2+
3+
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
12+
# Diagnostic reports (https://nodejs.org/api/report.html)
13+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
14+
15+
# Runtime data
16+
pids
17+
*.pid
18+
*.seed
19+
*.pid.lock
20+
21+
# Directory for instrumented libs generated by jscoverage/JSCover
22+
lib-cov
23+
24+
# Coverage directory used by tools like istanbul
25+
coverage
26+
*.lcov
27+
28+
# nyc test coverage
29+
.nyc_output
30+
31+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32+
.grunt
33+
34+
# Bower dependency directory (https://bower.io/)
35+
bower_components
36+
37+
# node-waf configuration
38+
.lock-wscript
39+
40+
# Compiled binary addons (https://nodejs.org/api/addons.html)
41+
build/Release
42+
43+
# Dependency directories
44+
node_modules/
45+
jspm_packages/
46+
47+
# TypeScript v1 declaration files
48+
typings/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Optional REPL history
60+
.node_repl_history
61+
62+
# Output of 'npm pack'
63+
*.tgz
64+
65+
# Yarn Integrity file
66+
.yarn-integrity
67+
68+
# dotenv environment variables file
69+
.env
70+
.env.test
71+
72+
# parcel-bundler cache (https://parceljs.org/)
73+
.cache
74+
75+
# next.js build output
76+
.next
77+
78+
# nuxt.js build output
79+
.nuxt
80+
81+
# vuepress build output
82+
.vuepress/dist
83+
84+
# Serverless directories
85+
.serverless/
86+
87+
# FuseBox cache
88+
.fusebox/
89+
90+
# DynamoDB Local files
91+
.dynamodb/

‎LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2019, Fusion Engineering <oss@fusion.engineering>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

‎README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Configuring credentials
2+
3+
This action allows you to clone private repositories from GitHub by providing a `GIT_CREDENTIALS` secret.
4+
5+
The contents of `GIT_CREDENTIALTS` will be saved in the `$XDG_CONFIG_HOME/git/credentials` file,
6+
and git will be configured to use these credentials.
7+
The credentials file contains a list of URL patterns with authentication information.
8+
See `man 7 git-credentials-store` for more details.
9+
10+
Additionally, `ssh` URLs for github repositories will be rewritten to `https`, so the credentials can be used.
11+
12+
It is advisable to generate an access token specifically for your workflow / actions.
13+
Simply use the token in place of the password in the `GIT_CREDENTIALS`:
14+
15+
```
16+
https://$username:$token@github.com/
17+
```
18+
19+
# Why not use an SSH key?
20+
Currently, Cargo (the Rust package manager) does not support SSH authentication other than through an SSH agent.
21+
SSH agents are not meant to be used non-interactively, so HTTPS authentication is a simpler solution.
22+
23+
If you can use plain SSH keys, that would be a good solution too.

‎action.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: setup-git-credentials
2+
description: Allow cloning of private repositories from GitHub
3+
author: Fusion Engineering
4+
inputs:
5+
secret:
6+
description: secret containing the git credentials
7+
default: GIT_CREDENTIALS
8+
9+
runs:
10+
using: node12
11+
main: lib/main.js

‎package-lock.json

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "setup-git-credentials",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "Allow cloning private repositories from GitHub",
6+
"main": "lib/main.js",
7+
"scripts": {
8+
"build": "tsc"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/fusion-engineering/setup-git-credentials.git"
13+
},
14+
"keywords": [
15+
"git",
16+
"private",
17+
"clone"
18+
],
19+
"author": "Fusion Engineering",
20+
"license": "BSD-2-Clause",
21+
"dependencies": {
22+
"@actions/core": "^1.0.0",
23+
"@actions/exec": "^1.0.0"
24+
},
25+
"devDependencies": {
26+
"@types/node": "^12.0.4",
27+
"typescript": "^3.5.1"
28+
}
29+
}

‎src/main.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as core from '@actions/core';
2+
import { exec } from '@actions/exec';
3+
4+
import { promises as fs } from 'fs';
5+
import * as process from 'process';
6+
import * as os from 'os';
7+
8+
function xdg_config_home() {
9+
const xdg_config_home = process.env['XGD_CONFIG_HOME'];
10+
if (xdg_config_home) return xdg_config_home;
11+
return `${os.homedir()}/.config`
12+
}
13+
14+
async function run() {
15+
const secret = core.getInput('secret');
16+
const credentials = process.env[secret];
17+
if (!credentials) {
18+
throw new Error(`Credentials environment variable '${secret}' is not set`);
19+
}
20+
21+
// Write credentials.
22+
await fs.mkdir(`${xdg_config_home()}/git`, { recursive: true });
23+
await fs.writeFile(`${xdg_config_home()}/git/credentials`, credentials, { flag: 'a', mode: 0o600 });
24+
25+
// Add git configuration.
26+
await exec('git', ['config', '--global', 'credential.helper', 'store']);
27+
await exec('git', ['config', '--global', 'url.https://github.com/.insteadOf', 'ssh://git@github.com/']);
28+
await exec('git', ['config', '--global', 'url.https://github.com/.insteadOf', 'git@github.com:']);
29+
}
30+
31+
try {
32+
run();
33+
} catch (error) {
34+
core.setFailed(error.message);
35+
}

‎tsconfig.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"incremental": true,
4+
"target": "es6",
5+
"module": "commonjs",
6+
"outDir": "./lib",
7+
"rootDir": "./src",
8+
9+
"strict": true,
10+
"noImplicitAny": true,
11+
"strictNullChecks": true,
12+
"strictFunctionTypes": true,
13+
"strictBindCallApply": true,
14+
"strictPropertyInitialization": true,
15+
"noImplicitThis": true,
16+
"alwaysStrict": true,
17+
"noUnusedLocals": true,
18+
"noUnusedParameters": true,
19+
"noImplicitReturns": true,
20+
"noFallthroughCasesInSwitch": true,
21+
22+
"esModuleInterop": true,
23+
24+
"inlineSourceMap": true,
25+
"inlineSources": true
26+
},
27+
28+
"exclude": ["node_modules"]
29+
}

0 commit comments

Comments
 (0)
Please sign in to comment.