Skip to content

Commit

Permalink
chore(release): 1.3.0
Browse files Browse the repository at this point in the history
# [1.3.0](v1.2.0...v1.3.0) (2020-08-25)

### Bug Fixes

* typo in GithubLocation class definition ([0ea810a](0ea810a))

### Features

* location input ([25b4a18](25b4a18))
  • Loading branch information
gliech committed Aug 25, 2020
1 parent 6b5c7e1 commit d166f6e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
43 changes: 28 additions & 15 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12463,34 +12463,47 @@ const core = __webpack_require__(186);
const github = __webpack_require__(438);
const sodium = __webpack_require__(637);

class GithubLocation {
constructor(location_input) {
if (location_input) {
const [owner, repo] = location_input.split('/')
this.data = {owner, repo}
} else {
const context = github.context;
this.data = context.repo;
}
}
toString() {
return [this.data.owner, this.data.repo].join('/')
}
}

async function run() {
try {
// Get all inputs
const pa_token = core.getInput('pa_token');
const octokit = github.getOctokit(pa_token);

const secret_name = core.getInput('name');

const secret_value = core.getInput('value');
core.setSecret(secret_value);
const input_pat = core.getInput('pa_token');
const input_location = core.getInput('location');
const input_name = core.getInput('name');
const input_value = core.getInput('value');

const context = github.context;
const secret_location = new GithubLocation(input_location)

// Retrieve repository public key and encrypt secret value
core.info(`Retrieving public key for repository ${context.repo.owner}/${context.repo.repo}`)
const { data: repo_public_key } = await octokit.actions.getRepoPublicKey(context.repo);
const octokit = github.getOctokit(input_pat);
core.info(`Retrieving public key for repository ${secret_location}`)
const { data: repo_public_key } = await octokit.actions.getRepoPublicKey(secret_location.data);

core.info("Encrypting secret value")
const plain_value_bytes = Buffer.from(secret_value);
const plain_value_bytes = Buffer.from(input_value);
const public_key_bytes = Buffer.from(repo_public_key.key, 'base64');
const secret_value_bytes = sodium.seal(plain_value_bytes, public_key_bytes);
const signed_secret_value = Buffer.from(secret_value_bytes).toString('base64');

// Create or update secret
core.info(`Setting repository secret "${secret_name}"`)
core.info(`Setting repository secret "${input_name}"`)
const { status } = await octokit.actions.createOrUpdateRepoSecret({
...context.repo,
secret_name: secret_name,
...secret_location.data,
secret_name: input_name,
encrypted_value: signed_secret_value,
key_id: repo_public_key.key_id
});
Expand All @@ -12501,7 +12514,7 @@ async function run() {
}

if (status in response_codes) {
core.info(`Successfully ${response_codes[status]} repository secret "${secret_name}"`)
core.info(`Successfully ${response_codes[status]} repository secret "${input_name}"`)
}

core.setOutput("status", status);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-github-secret-action",
"version": "1.2.0",
"version": "1.3.0",
"private": "true",
"description": "Create or update a Github Secret",
"main": "dist/index.js",
Expand Down

0 comments on commit d166f6e

Please sign in to comment.