Skip to content
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

git: alternative github context and additional methods #55

Merged
merged 1 commit into from
Mar 2, 2023

Conversation

crazy-max
Copy link
Member

follow-up docker/metadata-action#248

Adds alternative context to the GitHub one for Git.

@neilime PTAL. I keep you posted when we cut a new release of the actions-toolkit so you can rebase your PR on the metadata-action repo. You could then have smth like:

---
 src/context.ts | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/context.ts b/src/context.ts
index 3738b23..dd819c9 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -1,7 +1,11 @@
 import * as core from '@actions/core';
+import {Context} from '@actions/github/lib/context';
+import {Git} from '@docker/actions-toolkit/lib/git';
+import {GitHub} from '@docker/actions-toolkit/lib/github';
 import {Util} from '@docker/actions-toolkit/lib/util';
 
 export interface Inputs {
+  context: Context;
   images: string[];
   tags: string[];
   flavor: string[];
@@ -12,8 +16,9 @@ export interface Inputs {
   githubToken: string;
 }
 
-export function getInputs(): Inputs {
+export async function getInputs(): Promise<Inputs> {
   return {
+    context: await getContextInput('context'),
     images: Util.getInputList('images', {ignoreComma: true}),
     tags: Util.getInputList('tags', {ignoreComma: true}),
     flavor: Util.getInputList('flavor', {ignoreComma: true}),
@@ -24,3 +29,20 @@ export function getInputs(): Inputs {
     githubToken: core.getInput('github-token')
   };
 }
+
+export enum ContextSource {
+  workflow = 'workflow',
+  git = 'git'
+}
+
+async function getContextInput(name: string): Promise<Context> {
+  const input = core.getInput(name);
+  switch (input) {
+    case ContextSource.workflow:
+      return GitHub.context;
+    case ContextSource.git:
+      return await Git.context();
+    default:
+      throw new Error(`Invalid context: ${input}`);
+  }
+}

@crazy-max crazy-max force-pushed the git-context branch 2 times, most recently from 442a46c to b8325fe Compare February 25, 2023 06:08
@crazy-max crazy-max marked this pull request as ready for review February 25, 2023 11:13
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
@crazy-max crazy-max merged commit 53ca96f into docker:main Mar 2, 2023
@crazy-max crazy-max deleted the git-context branch March 2, 2023 14:50
@neilime
Copy link
Contributor

neilime commented Mar 3, 2023

@crazy-max I've done the job on docker/metadata-action#248, waiting for you review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants