Use url fragment for git ref context

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
pull/92/head
CrazyMax 2020-08-17 17:31:15 +02:00
parent 8413351ed4
commit e7964906a6
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
5 changed files with 5 additions and 83 deletions

View File

@ -89,9 +89,8 @@ jobs:
uses: ./
env:
GIT_AUTH_TOKEN: ${{ github.token }}
GIT_REF: ${{ github.ref }}
with:
context: ${{ github.repositoryUrl }}
context: "${{ github.repositoryUrl }}#${{ github.ref }}"
file: ./test/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64

View File

@ -158,9 +158,8 @@ jobs:
uses: ./
env:
GIT_AUTH_TOKEN: ${{ github.token }}
GIT_REF: ${{ github.ref }}
with:
context: ${{ github.repositoryUrl }}
context: "${{ github.repositoryUrl }}#${{ github.ref }}"
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64,linux/386
push: true
@ -178,7 +177,7 @@ Following inputs can be used as `step.with` keys
| Name | Type | Default | Description |
|---------------------|---------|-----------------------------------|------------------------------------|
| `builder` | String | | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) |
| `context` | String | `.` | Build's context is the set of files located in the specified `PATH` or `URL` |
| `context` | String | `.` | Build's context is the set of files located in the specified [`PATH` or `URL`](https://docs.docker.com/engine/reference/commandline/build/) |
| `file` | String | `./Dockerfile` | Path to the Dockerfile. |
| `build-args` | List | | List of build-time variables |
| `labels` | List | | List of metadata for an image |
@ -223,7 +222,6 @@ Following environment variables can be used as `step.env` keys
|--------------------------|---------------------------------------|
| `GIT_AUTH_HEADER`**¹** | Raw authorization header to authenticate against git repository |
| `GIT_AUTH_TOKEN`**¹** | `x-access-token` basic auth to authenticate against git repository |
| `GIT_REF`**¹** | Git refrerence to use against git repository |
> **¹** Only used if `input.context` is a valid git uri.

View File

@ -28,11 +28,9 @@
"dependencies": {
"@actions/cache": "^1.0.2",
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4",
"git-url-parse": "^11.1.3"
"@actions/exec": "^1.0.4"
},
"devDependencies": {
"@types/git-url-parse": "^9.0.0",
"@types/jest": "^26.0.3",
"@types/node": "^14.0.14",
"@zeit/ncc": "^0.22.3",

View File

@ -1,4 +1,3 @@
import gitUrlParse from 'git-url-parse';
import * as core from '@actions/core';
export interface Inputs {
@ -26,7 +25,7 @@ export interface Inputs {
export async function getInputs(): Promise<Inputs> {
return {
context: await getBuildContext(),
context: core.getInput('context') || '.',
file: core.getInput('file') || './Dockerfile',
buildArgs: await getInputList('build-args'),
labels: await getInputList('labels'),
@ -68,23 +67,6 @@ export async function getArgs(inputs: Inputs): Promise<Array<string>> {
return args;
}
async function getBuildContext(): Promise<string> {
let context: string = core.getInput('context');
if (!context) {
return '.';
}
try {
const gitUrl = gitUrlParse(context);
const gitRef = process.env['GIT_REF'] || '';
if (gitRef) {
return `${gitUrl.toString()}#${gitRef}`;
}
return gitUrl.toString();
} catch {
return context;
}
}
async function getCommonArgs(inputs: Inputs): Promise<Array<string>> {
let args: Array<string> = [];
if (inputs.noCache) {

View File

@ -712,11 +712,6 @@
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
"@types/git-url-parse@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@types/git-url-parse/-/git-url-parse-9.0.0.tgz#aac1315a44fa4ed5a52c3820f6c3c2fb79cbd12d"
integrity sha512-kA2RxBT/r/ZuDDKwMl+vFWn1Z0lfm1/Ik6Qb91wnSzyzCDa/fkM8gIOq6ruB7xfr37n6Mj5dyivileUVKsidlg==
"@types/graceful-fs@^4.1.2":
version "4.1.3"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f"
@ -1769,21 +1764,6 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"
git-up@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/git-up/-/git-up-4.0.2.tgz#10c3d731051b366dc19d3df454bfca3f77913a7c"
integrity sha512-kbuvus1dWQB2sSW4cbfTeGpCMd8ge9jx9RKnhXhuJ7tnvT+NIrTVfYZxjtflZddQYcmdOTlkAcjmx7bor+15AQ==
dependencies:
is-ssh "^1.3.0"
parse-url "^5.0.0"
git-url-parse@^11.1.3:
version "11.1.3"
resolved "https://registry.yarnpkg.com/git-url-parse/-/git-url-parse-11.1.3.tgz#03625b6fc09905e9ad1da7bb2b84be1bf9123143"
integrity sha512-GPsfwticcu52WQ+eHp0IYkAyaOASgYdtsQDIt4rUp6GbiNt1P9ddrh3O0kQB0eD4UJZszVqNT3+9Zwcg40fywA==
dependencies:
git-up "^4.0.0"
glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
@ -2048,13 +2028,6 @@ is-potential-custom-element-name@^1.0.0:
resolved "https://registry.yarnpkg.com/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.0.tgz#0c52e54bcca391bb2c494b21e8626d7336c6e397"
integrity sha1-DFLlS8yjkbssSUsh6GJtczbG45c=
is-ssh@^1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/is-ssh/-/is-ssh-1.3.2.tgz#a4b82ab63d73976fd8263cceee27f99a88bdae2b"
integrity sha512-elEw0/0c2UscLrNG+OAorbP539E3rhliKPg+hDMWN9VwrDXfYK+4PBEykDPfxlYYtQvl84TascnQyobfQLHEhQ==
dependencies:
protocols "^1.1.0"
is-stream@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
@ -2921,11 +2894,6 @@ normalize-path@^3.0.0:
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
normalize-url@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
npm-run-path@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
@ -3038,24 +3006,6 @@ parse-json@^5.0.0:
json-parse-better-errors "^1.0.1"
lines-and-columns "^1.1.6"
parse-path@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/parse-path/-/parse-path-4.0.2.tgz#ef14f0d3d77bae8dd4bc66563a4c151aac9e65aa"
integrity sha512-HSqVz6iuXSiL8C1ku5Gl1Z5cwDd9Wo0q8CoffdAghP6bz8pJa1tcMC+m4N+z6VAS8QdksnIGq1TB6EgR4vPR6w==
dependencies:
is-ssh "^1.3.0"
protocols "^1.4.0"
parse-url@^5.0.0:
version "5.0.2"
resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-5.0.2.tgz#856a3be1fcdf78dc93fc8b3791f169072d898b59"
integrity sha512-Czj+GIit4cdWtxo3ISZCvLiUjErSo0iI3wJ+q9Oi3QuMYTI6OZu+7cewMWZ+C1YAnKhYTk6/TLuhIgCypLthPA==
dependencies:
is-ssh "^1.3.0"
normalize-url "^3.3.0"
parse-path "^4.0.0"
protocols "^1.4.0"
parse5@5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178"
@ -3163,11 +3113,6 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.4"
protocols@^1.1.0, protocols@^1.4.0:
version "1.4.8"
resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.8.tgz#48eea2d8f58d9644a4a32caae5d5db290a075ce8"
integrity sha512-IgjKyaUSjsROSO8/D49Ab7hP8mJgTYcqApOqdPhLoPxAplXmkp+zRvsrSQjFn5by0rhm4VH0GAUELIPpx7B1yg==
pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"