-
Notifications
You must be signed in to change notification settings - Fork 38
build: git context query format support #809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,14 +17,15 @@ | |
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import * as core from '@actions/core'; | ||
| import * as github from '@actions/github'; | ||
| import {parse} from 'csv-parse/sync'; | ||
|
|
||
| import {Buildx} from './buildx'; | ||
| import {Context} from '../context'; | ||
| import {GitHub} from '../github'; | ||
| import {Util} from '../util'; | ||
|
|
||
| import {BuildMetadata} from '../types/buildx/build'; | ||
| import {BuildMetadata, GitContextFormat} from '../types/buildx/build'; | ||
| import {VertexWarning} from '../types/buildkit/client'; | ||
| import {ProvenancePredicate} from '../types/intoto/slsa_provenance/v0.2/provenance'; | ||
|
|
||
|
|
@@ -48,6 +49,32 @@ export class Build { | |
| this.metadataFilename = `build-metadata-${Util.generateRandomString()}.json`; | ||
| } | ||
|
|
||
| public async gitContext(ref?: string, sha?: string, format?: GitContextFormat): Promise<string> { | ||
| const setPullRequestHeadRef: boolean = !!(process.env.DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF && process.env.DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF === 'true'); | ||
| ref = ref || github.context.ref; | ||
| sha = sha || github.context.sha; | ||
| if (!ref.startsWith('refs/')) { | ||
| ref = `refs/heads/${ref}`; | ||
| } else if (ref.startsWith(`refs/pull/`) && setPullRequestHeadRef) { | ||
| ref = ref.replace(/\/merge$/g, '/head'); | ||
| } | ||
| const baseURL = `${GitHub.serverURL}/${github.context.repo.owner}/${github.context.repo.repo}.git`; | ||
| if (!format) { | ||
| if (await this.buildx.versionSatisfies('>=0.29.0')) { | ||
| format = 'query'; | ||
| } else { | ||
| format = 'fragment'; | ||
| } | ||
|
Comment on lines
+63
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaults to There will be a follow-up on build-push-action and bake-action to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still depends on the dockerfile version as well, so not sure if we can change default before |
||
| } | ||
| if (format === 'query') { | ||
| return `${baseURL}?ref=${ref}${sha !== '' ? `&checksum=${sha}` : ''}`; | ||
| } | ||
| if (sha && !ref.startsWith(`refs/pull/`)) { | ||
| return `${baseURL}#${sha}`; | ||
| } | ||
| return `${baseURL}#${ref}`; | ||
| } | ||
|
|
||
| public getImageIDFilePath(): string { | ||
| return path.join(Context.tmpDir(), this.iidFilename); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.