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

Commit

Permalink
Merge pull request #5 from matootie/feature/minimal-input
Browse files Browse the repository at this point in the history
Reduce required input
  • Loading branch information
matootie authored Dec 29, 2019
2 parents 1aaa142 + 6a0fb56 commit 781d3c4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 50 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
name: "Test Run"
on:
push:
paths:
paths:
- "dist/index.js"
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v1
- name: Run the Action
id: run-action
uses: ./
with:
username: matootie
personalAccessToken: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Test output
run: echo ${{ steps.run-action.outputs.imageURL }}
- name: Checkout Repository
uses: actions/checkout@v2
- name: Run the Action
id: run-action
uses: ./
with:
accessToken: ${{ secrets.GITHUB_TOKEN }}
- name: Test output
run: echo ${{ steps.run-action.outputs.imageURL }}
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ Build and publish your repository as a Docker image and push it to GitHub Packag

## Inputs

### `username`
### `accessToken`

**Required**. GitHub user to publish the image on behalf of.
**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 }}`.

### `personalAccessToken`
### `username`

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

### `repositoryName`

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

### `imageName`

Optional. The desired name for the image. Defaults to current repository name.
*Optional*. The desired name for the image. Defaults to current repository name.

### `imageTag`

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

## Outputs

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

```yaml
- name: Checkout Repository
uses: actions/checkout@v2
- name: Publish Image
uses: matootie/github-docker@v1.0.1
uses: matootie/github-docker@v2.0.0
with:
username: matootie
personalAccessToken: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
accessToken: ${{ secrets.GITHUB_TOKEN }}
```
34 changes: 19 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
name: 'GitHub Docker Action'
description: 'Build and publish your repository as a Docker image and push it to GitHub Package Registry in one step'
name: "GitHub Docker Action"
description: "Build and publish your repository as a Docker image and push it to GitHub Package Registry in one step"
inputs:
username:
description: 'GitHub user to publish the image on behalf of.'
required: true
personalAccessToken:
description: 'GitHub Personal Access Token for the user.'
accessToken:
description: "GitHub Repository Token to log in using."
required: true
context:
description: "Where should GitHub Docker find the Dockerfile, relative to the root of the repository."
required: false
default: "."
username:
description: "GitHub user to publish the image on behalf of."
required: false
repositoryName:
description: 'The repository to push the image to. Defaults to current repository. Must be specified in format user/repo'
description: "The repository to push the image to. Defaults to current repository. Must be specified in format user/repo"
required: false
imageName:
description: 'The desired name for the image. Defaults to current repository name.'
description: "The desired name for the image. Defaults to current repository name."
required: false
imageTag:
description: 'The desired tag for the image. Defaults to current branch or release version number.'
description: "The desired tag for the image. Defaults to current branch or release version number."
required: false
outputs:
imageURL:
description: 'The URL of the image.'
description: "The URL of the image."
runs:
using: 'node12'
main: 'dist/index.js'
using: "node12"
main: "dist/index.js"
branding:
icon: 'anchor'
color: 'blue'
icon: "anchor"
color: "blue"
25 changes: 19 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ module.exports = require("os");
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {

const process = __webpack_require__(765);
const path = __webpack_require__(622);
const core = __webpack_require__(470);
const exec = __webpack_require__(986);

Expand Down Expand Up @@ -663,12 +664,16 @@ async function run() {
*/

// Set the workspace directory.
// Set the workspace directory and context.
const home = process.env['HOME'];
const workspace = process.env['GITHUB_WORKSPACE'];
const context = core.getInput('context', { required: true });
path.join(workspace, context);

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

// Set some variables.
const imageURL = `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`

// Build the Docker image.
await exec.exec(
`docker`,
['build', '--tag', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`, workspace]);
['build', '--tag', imageURL, workspace]);

// Push the Docker image.
await exec.exec(
`docker`,
['push', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`]);
['push', imageURL]);

// Output the image URL.
core.setOutput('imageURL', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`);
core.setOutput('imageURL', imageURL);

// Delete the Docker config.
exec.exec(
'rm',
['-v', `${home}/.docker/config.json`]);
}
catch (error) {
core.setFailed(error.message);
Expand Down
25 changes: 19 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const process = require('process');
const path = require('path');
const core = require('@actions/core');
const exec = require('@actions/exec');

Expand Down Expand Up @@ -27,12 +28,16 @@ async function run() {
*/

// Set the workspace directory.
// Set the workspace directory and context.
const home = process.env['HOME'];
const workspace = process.env['GITHUB_WORKSPACE'];
const context = core.getInput('context', { required: true });
path.join(workspace, context);

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

// Set some variables.
const imageURL = `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`

// Build the Docker image.
await exec.exec(
`docker`,
['build', '--tag', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`, workspace]);
['build', '--tag', imageURL, workspace]);

// Push the Docker image.
await exec.exec(
`docker`,
['push', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`]);
['push', imageURL]);

// Output the image URL.
core.setOutput('imageURL', `docker.pkg.github.com/${repository}/${imageName}:${imageTag}`);
core.setOutput('imageURL', imageURL);

// Delete the Docker config.
exec.exec(
'rm',
['-v', `${home}/.docker/config.json`]);
}
catch (error) {
core.setFailed(error.message);
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": "github-docker",
"version": "1.0.0",
"version": "2.0.0",
"description": "Build and publish your repository as a Docker image and push it to GitHub Package Registry in one step",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 781d3c4

Please sign in to comment.