Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
docker
/
metadata-action
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Security
Insights
Additional navigation options
Code
Pull requests
Actions
Security
Insights
Files
8f8c795
.github
__tests__
dist
src
context.ts
flavor.ts
image.ts
main.ts
meta.ts
pep440.d.ts
tag.ts
test
.dockerignore
.editorconfig
.eslintrc.json
.gitattributes
.gitignore
.prettierrc.json
LICENSE
README.md
UPGRADE.md
action.yml
codecov.yml
dev.Dockerfile
docker-bake.hcl
jest.config.ts
package.json
tsconfig.json
yarn.lock
Breadcrumbs
metadata-action
/
src
/
context.ts
Blame
Blame
Latest commit
History
History
73 lines (64 loc) · 2.45 KB
Breadcrumbs
metadata-action
/
src
/
context.ts
Top
File metadata and controls
Code
Blame
73 lines (64 loc) · 2.45 KB
Raw
import * as core from '@actions/core'; import {Context} from '@actions/github/lib/context'; import {Util} from '@docker/actions-toolkit/lib/util'; import {Git} from '@docker/actions-toolkit/lib/git'; import {GitHub} from '@docker/actions-toolkit/lib/github'; export interface Inputs { context: ContextSource; images: string[]; tags: string[]; flavor: string[]; labels: string[]; sepTags: string; sepLabels: string; bakeTarget: string; githubToken: string; } export function getInputs(): Inputs { return { context: (core.getInput('context') || ContextSource.workflow) as ContextSource, images: Util.getInputList('images', {ignoreComma: true}), tags: Util.getInputList('tags', {ignoreComma: true}), flavor: Util.getInputList('flavor', {ignoreComma: true}), labels: Util.getInputList('labels', {ignoreComma: true}), sepTags: core.getInput('sep-tags', {trimWhitespace: false}) || `\n`, sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`, bakeTarget: core.getInput('bake-target') || `docker-metadata-action`, githubToken: core.getInput('github-token') }; } export enum ContextSource { workflow = 'workflow', git = 'git' } export async function getContext(source: ContextSource): Promise<Context> { switch (source) { case ContextSource.workflow: return getContextFromWorkflow(); case ContextSource.git: return await getContextFromGit(); default: throw new Error(`Invalid context source: ${source}`); } } function getContextFromWorkflow(): Context { const context = GitHub.context; // Needs to override Git reference with pr ref instead of upstream branch ref // for pull_request_target event // https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target if (/pull_request_target/.test(context.eventName)) { context.ref = `refs/pull/${context.payload.number}/merge`; } // DOCKER_METADATA_PR_HEAD_SHA env var can be used to set associated head // SHA instead of commit SHA that triggered the workflow on pull request // event. if (/true/i.test(process.env.DOCKER_METADATA_PR_HEAD_SHA || '')) { if ((/pull_request/.test(context.eventName) || /pull_request_target/.test(context.eventName)) && context.payload?.pull_request?.head?.sha != undefined) { context.sha = context.payload.pull_request.head.sha; } } return context; } async function getContextFromGit(): Promise<Context> { return await Git.context(); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
You can’t perform that action at this time.