From d9bd237328f97c6d63482446e2e8fc56e71a1bd9 Mon Sep 17 00:00:00 2001 From: Mateja Lasan Date: Sat, 28 Dec 2019 18:37:32 -0500 Subject: [PATCH 1/8] Rework required inputs .github/workflows/test.yml | 21 ++++++++++----------- README.md | 21 +++++++++++---------- action.yml | 34 +++++++++++++++++++--------------- dist/index.js | 18 +++++++++++++----- index.js | 18 +++++++++++++----- package.json | 4 ++-- 6 files changed, 68 insertions(+), 48 deletions(-) --- .github/workflows/test.yml | 21 ++++++++++----------- README.md | 21 +++++++++++---------- action.yml | 34 +++++++++++++++++++--------------- dist/index.js | 18 +++++++++++++----- index.js | 18 +++++++++++++----- package.json | 4 ++-- 6 files changed, 68 insertions(+), 48 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49eac4c..998ba37 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: + personalAccessToken: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + - name: Test output + run: echo ${{ steps.run-action.outputs.imageURL }} diff --git a/README.md b/README.md index 973009c..171b189 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 }} ``` diff --git a/action.yml b/action.yml index f5547a9..86b7b17 100644 --- a/action.yml +++ b/action.yml @@ -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 Token for the user. Consider using ${{ secrets.GITHUB_TOKEN }}." 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" diff --git a/dist/index.js b/dist/index.js index 5ded4d5..6150662 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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); @@ -665,10 +666,13 @@ async function run() { // Set the workspace directory. 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 }); + const 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]); @@ -690,18 +694,22 @@ 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], + { env: { DOCKER_BUILDKIT: '1' } }); // 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); } catch (error) { core.setFailed(error.message); diff --git a/index.js b/index.js index 9d5cfc4..39890ac 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const process = require('process'); +const path = require('path'); const core = require('@actions/core'); const exec = require('@actions/exec'); @@ -29,10 +30,13 @@ async function run() { // Set the workspace directory. 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 }); + const 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]); @@ -54,18 +58,22 @@ 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], + { env: { DOCKER_BUILDKIT: '1' } }); // 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); } catch (error) { core.setFailed(error.message); diff --git a/package.json b/package.json index b901545..8193d96 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -31,4 +31,4 @@ "@zeit/ncc": "^0.20.5", "eslint": "^6.3.0" } -} +} \ No newline at end of file From 26245d4b1ec9d7f479c7db18ade2091a132cfe4b Mon Sep 17 00:00:00 2001 From: Mateja Lasan Date: Sat, 28 Dec 2019 18:40:45 -0500 Subject: [PATCH 2/8] Fix action.yml file action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 86b7b17..7f6f540 100644 --- a/action.yml +++ b/action.yml @@ -2,7 +2,7 @@ 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: accessToken: - description: "GitHub Token for the user. Consider using ${{ secrets.GITHUB_TOKEN }}." + 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." From c0b703ccd9eeb3ddfdf32b91c8b270c85e8ac01d Mon Sep 17 00:00:00 2001 From: Mateja Lasan Date: Sat, 28 Dec 2019 18:42:48 -0500 Subject: [PATCH 3/8] Documenting dist/index.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- dist/index.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6150662..2e58904 100644 --- a/dist/index.js +++ b/dist/index.js @@ -664,7 +664,7 @@ async function run() { */ - // Set the workspace directory. + // Set the workspace directory and context. const workspace = process.env['GITHUB_WORKSPACE']; const context = core.getInput('context', { required: true }); path.join(workspace, context); diff --git a/index.js b/index.js index 39890ac..dce96a4 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ async function run() { */ - // Set the workspace directory. + // Set the workspace directory and context. const workspace = process.env['GITHUB_WORKSPACE']; const context = core.getInput('context', { required: true }); path.join(workspace, context); From 11153f6db5abff65d921909a4040f7a9058d005c Mon Sep 17 00:00:00 2001 From: Mateja Lasan Date: Sat, 28 Dec 2019 18:44:22 -0500 Subject: [PATCH 4/8] Fix dist/index.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- dist/index.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2e58904..031f5b0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -670,7 +670,7 @@ async function run() { path.join(workspace, context); // Log in to Docker. - const username = core.getInput('username', { required: false }); + let username = core.getInput('username', { required: false }); if (!username) username = process.env['GITHUB_ACTOR']; const password = core.getInput('accessToken', { required: true }); await exec.exec( diff --git a/index.js b/index.js index dce96a4..ae66cc3 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ async function run() { path.join(workspace, context); // Log in to Docker. - const username = core.getInput('username', { required: false }); + let username = core.getInput('username', { required: false }); if (!username) username = process.env['GITHUB_ACTOR']; const password = core.getInput('accessToken', { required: true }); await exec.exec( From dfc3a4bd72df63941f2a9faf2f7c6c14c28a15e0 Mon Sep 17 00:00:00 2001 From: Mateja Lasan Date: Sat, 28 Dec 2019 18:45:55 -0500 Subject: [PATCH 5/8] Update workflow .github/workflows/test.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) --- .github/workflows/test.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 998ba37..c655d73 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,5 @@ name: "Test Run" -on: - push: - paths: - - "dist/index.js" +on: push jobs: test: runs-on: ubuntu-latest @@ -13,6 +10,6 @@ jobs: id: run-action uses: ./ with: - personalAccessToken: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + accessToken: ${{ secrets.GITHUB_TOKEN }} - name: Test output run: echo ${{ steps.run-action.outputs.imageURL }} From 7bbce7081eb04a0b0690a7ea9074d78da9db88c7 Mon Sep 17 00:00:00 2001 From: Mateja Lasan Date: Sat, 28 Dec 2019 18:48:46 -0500 Subject: [PATCH 6/8] Update .github/workflows/test.yml | 5 ++++- dist/index.js | 3 +-- index.js | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) --- .github/workflows/test.yml | 5 ++++- dist/index.js | 3 +-- index.js | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c655d73..ec65028 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,8 @@ name: "Test Run" -on: push +on: + push: + paths: + - "dist/index.js" jobs: test: runs-on: ubuntu-latest diff --git a/dist/index.js b/dist/index.js index 031f5b0..f79def7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -700,8 +700,7 @@ async function run() { // Build the Docker image. await exec.exec( `docker`, - ['build', '--tag', imageURL, workspace], - { env: { DOCKER_BUILDKIT: '1' } }); + ['build', '--tag', imageURL, workspace]); // Push the Docker image. await exec.exec( diff --git a/index.js b/index.js index ae66cc3..8eb778c 100644 --- a/index.js +++ b/index.js @@ -64,8 +64,7 @@ async function run() { // Build the Docker image. await exec.exec( `docker`, - ['build', '--tag', imageURL, workspace], - { env: { DOCKER_BUILDKIT: '1' } }); + ['build', '--tag', imageURL, workspace]); // Push the Docker image. await exec.exec( From 3dff630760df5f10e41f0b87bdfb87f1c6cb71e2 Mon Sep 17 00:00:00 2001 From: Mateja Lasan Date: Sat, 28 Dec 2019 18:54:37 -0500 Subject: [PATCH 7/8] Delete config after success dist/index.js | 6 ++++++ index.js | 6 ++++++ 2 files changed, 12 insertions(+) --- dist/index.js | 6 ++++++ index.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/dist/index.js b/dist/index.js index f79def7..de14e70 100644 --- a/dist/index.js +++ b/dist/index.js @@ -665,6 +665,7 @@ async function run() { */ // 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); @@ -709,6 +710,11 @@ async function run() { // Output the image URL. core.setOutput('imageURL', imageURL); + + // Delete the Docker config. + exec.exec( + 'rm', + ['-v', `${home}/.docker/config.json`]); } catch (error) { core.setFailed(error.message); diff --git a/index.js b/index.js index 8eb778c..1a38566 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,7 @@ async function run() { */ // 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); @@ -73,6 +74,11 @@ async function run() { // Output the image URL. core.setOutput('imageURL', imageURL); + + // Delete the Docker config. + exec.exec( + 'rm', + ['-v', `${home}/.docker/config.json`]); } catch (error) { core.setFailed(error.message); From 6a0fb5608f6db13c78e7f0ce8ba1861c4965348a Mon Sep 17 00:00:00 2001 From: Mateja Lasan Date: Sat, 28 Dec 2019 18:59:18 -0500 Subject: [PATCH 8/8] Update npm packages package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0f07632..3f5ba21 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "github-docker", - "version": "1.0.0", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8193d96..44d48fd 100644 --- a/package.json +++ b/package.json @@ -31,4 +31,4 @@ "@zeit/ncc": "^0.20.5", "eslint": "^6.3.0" } -} \ No newline at end of file +}