Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit 781d3c4

Browse files
authored
Merge pull request #5 from matootie/feature/minimal-input
Reduce required input
2 parents 1aaa142 + 6a0fb56 commit 781d3c4

7 files changed

Lines changed: 80 additions & 50 deletions

File tree

.github/workflows/test.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
name: "Test Run"
22
on:
33
push:
4-
paths:
4+
paths:
55
- "dist/index.js"
66
jobs:
77
test:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Checkout Repository
11-
uses: actions/checkout@v1
12-
- name: Run the Action
13-
id: run-action
14-
uses: ./
15-
with:
16-
username: matootie
17-
personalAccessToken: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
18-
- name: Test output
19-
run: echo ${{ steps.run-action.outputs.imageURL }}
10+
- name: Checkout Repository
11+
uses: actions/checkout@v2
12+
- name: Run the Action
13+
id: run-action
14+
uses: ./
15+
with:
16+
accessToken: ${{ secrets.GITHUB_TOKEN }}
17+
- name: Test output
18+
run: echo ${{ steps.run-action.outputs.imageURL }}

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ Build and publish your repository as a Docker image and push it to GitHub Packag
44

55
## Inputs
66

7-
### `username`
7+
### `accessToken`
88

9-
**Required**. GitHub user to publish the image on behalf of.
9+
**Required**. GitHub Token for the user. Must have write permissions for packages. Recommended set up would be to use the provided GitHub Token for your repository; `${{ secrets.GITHUB_TOKEN }}`.
1010

11-
### `personalAccessToken`
11+
### `username`
1212

13-
**Required**. GitHub Personal Access Token for the user. Must have write permissions for packages.
13+
*Optional*. GitHub user to publish the image on behalf of. Defaults to the user who triggered the action to run.
1414

1515
### `repositoryName`
1616

17-
Optional. The repository to push the image to. Defaults to current repository. Must be specified in format `user/repo`.
17+
*Optional*. The repository to push the image to. Defaults to current repository. Must be specified in format `user/repo`.
1818

1919
### `imageName`
2020

21-
Optional. The desired name for the image. Defaults to current repository name.
21+
*Optional*. The desired name for the image. Defaults to current repository name.
2222

2323
### `imageTag`
2424

25-
Optional. The desired tag for the image. Defaults to current branch or release version number.
25+
*Optional*. The desired tag for the image. Defaults to current branch or release version number.
2626

2727
## Outputs
2828

@@ -33,9 +33,10 @@ The full URL of the image.
3333
## Example usage
3434

3535
```yaml
36+
- name: Checkout Repository
37+
uses: actions/checkout@v2
3638
- name: Publish Image
37-
uses: matootie/github-docker@v1.0.1
39+
uses: matootie/github-docker@v2.0.0
3840
with:
39-
username: matootie
40-
personalAccessToken: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
41+
accessToken: ${{ secrets.GITHUB_TOKEN }}
4142
```

action.yml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
name: 'GitHub Docker Action'
2-
description: 'Build and publish your repository as a Docker image and push it to GitHub Package Registry in one step'
1+
name: "GitHub Docker Action"
2+
description: "Build and publish your repository as a Docker image and push it to GitHub Package Registry in one step"
33
inputs:
4-
username:
5-
description: 'GitHub user to publish the image on behalf of.'
6-
required: true
7-
personalAccessToken:
8-
description: 'GitHub Personal Access Token for the user.'
4+
accessToken:
5+
description: "GitHub Repository Token to log in using."
96
required: true
7+
context:
8+
description: "Where should GitHub Docker find the Dockerfile, relative to the root of the repository."
9+
required: false
10+
default: "."
11+
username:
12+
description: "GitHub user to publish the image on behalf of."
13+
required: false
1014
repositoryName:
11-
description: 'The repository to push the image to. Defaults to current repository. Must be specified in format user/repo'
15+
description: "The repository to push the image to. Defaults to current repository. Must be specified in format user/repo"
1216
required: false
1317
imageName:
14-
description: 'The desired name for the image. Defaults to current repository name.'
18+
description: "The desired name for the image. Defaults to current repository name."
1519
required: false
1620
imageTag:
17-
description: 'The desired tag for the image. Defaults to current branch or release version number.'
21+
description: "The desired tag for the image. Defaults to current branch or release version number."
1822
required: false
1923
outputs:
2024
imageURL:
21-
description: 'The URL of the image.'
25+
description: "The URL of the image."
2226
runs:
23-
using: 'node12'
24-
main: 'dist/index.js'
27+
using: "node12"
28+
main: "dist/index.js"
2529
branding:
26-
icon: 'anchor'
27-
color: 'blue'
30+
icon: "anchor"
31+
color: "blue"

dist/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ module.exports = require("os");
635635
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
636636

637637
const process = __webpack_require__(765);
638+
const path = __webpack_require__(622);
638639
const core = __webpack_require__(470);
639640
const exec = __webpack_require__(986);
640641

@@ -663,12 +664,16 @@ async function run() {
663664
664665
*/
665666

666-
// Set the workspace directory.
667+
// Set the workspace directory and context.
668+
const home = process.env['HOME'];
667669
const workspace = process.env['GITHUB_WORKSPACE'];
670+
const context = core.getInput('context', { required: true });
671+
path.join(workspace, context);
668672

669673
// Log in to Docker.
670-
const username = core.getInput('username', { required: true });
671-
const password = core.getInput('personalAccessToken', { required: true });
674+
let username = core.getInput('username', { required: false });
675+
if (!username) username = process.env['GITHUB_ACTOR'];
676+
const password = core.getInput('accessToken', { required: true });
672677
await exec.exec(
673678
`docker`,
674679
['login', 'docker.pkg.github.com', '--username', username, '--password', password]);
@@ -690,18 +695,26 @@ async function run() {
690695
const refArray = ref.split('/');
691696
if (!imageTag) imageTag = refArray[refArray.length - 1];
692697

698+
// Set some variables.
699+
const imageURL = `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`
700+
693701
// Build the Docker image.
694702
await exec.exec(
695703
`docker`,
696-
['build', '--tag', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`, workspace]);
704+
['build', '--tag', imageURL, workspace]);
697705

698706
// Push the Docker image.
699707
await exec.exec(
700708
`docker`,
701-
['push', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`]);
709+
['push', imageURL]);
702710

703711
// Output the image URL.
704-
core.setOutput('imageURL', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`);
712+
core.setOutput('imageURL', imageURL);
713+
714+
// Delete the Docker config.
715+
exec.exec(
716+
'rm',
717+
['-v', `${home}/.docker/config.json`]);
705718
}
706719
catch (error) {
707720
core.setFailed(error.message);

index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const process = require('process');
2+
const path = require('path');
23
const core = require('@actions/core');
34
const exec = require('@actions/exec');
45

@@ -27,12 +28,16 @@ async function run() {
2728
2829
*/
2930

30-
// Set the workspace directory.
31+
// Set the workspace directory and context.
32+
const home = process.env['HOME'];
3133
const workspace = process.env['GITHUB_WORKSPACE'];
34+
const context = core.getInput('context', { required: true });
35+
path.join(workspace, context);
3236

3337
// Log in to Docker.
34-
const username = core.getInput('username', { required: true });
35-
const password = core.getInput('personalAccessToken', { required: true });
38+
let username = core.getInput('username', { required: false });
39+
if (!username) username = process.env['GITHUB_ACTOR'];
40+
const password = core.getInput('accessToken', { required: true });
3641
await exec.exec(
3742
`docker`,
3843
['login', 'docker.pkg.github.com', '--username', username, '--password', password]);
@@ -54,18 +59,26 @@ async function run() {
5459
const refArray = ref.split('/');
5560
if (!imageTag) imageTag = refArray[refArray.length - 1];
5661

62+
// Set some variables.
63+
const imageURL = `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`
64+
5765
// Build the Docker image.
5866
await exec.exec(
5967
`docker`,
60-
['build', '--tag', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`, workspace]);
68+
['build', '--tag', imageURL, workspace]);
6169

6270
// Push the Docker image.
6371
await exec.exec(
6472
`docker`,
65-
['push', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`]);
73+
['push', imageURL]);
6674

6775
// Output the image URL.
68-
core.setOutput('imageURL', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`);
76+
core.setOutput('imageURL', imageURL);
77+
78+
// Delete the Docker config.
79+
exec.exec(
80+
'rm',
81+
['-v', `${home}/.docker/config.json`]);
6982
}
7083
catch (error) {
7184
core.setFailed(error.message);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-docker",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "Build and publish your repository as a Docker image and push it to GitHub Package Registry in one step",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)