Skip to content

Commit

Permalink
ohash
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslemammad committed Mar 21, 2024
1 parent 8084bec commit ae603c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/cli/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ declare global {
GITHUB_BASE_REF: string;
// The head ref or source branch of the pull request in a workflow run. This property is only set when the event that triggers a workflow run is either pull_request or pull_request_target. For example, feature-branch-1.
GITHUB_HEAD_REF: string;
// The URL of the GitHub server. For example: https://github.com.
GITHUB_SERVER_URL: string
// The owner and repository name. For example, octocat/Hello-World.
GITHUB_REPOSITORY: string;
// The commit SHA that triggered the workflow. The value of this commit SHA depends on the event that triggered the workflow. For more information, see "Events that trigger workflows." For example, ffac537e6cbbf934b08745a378932722df287a53.
GITHUB_SHA: string;
// The account ID of the person or app that triggered the initial workflow run. For example, 1234567. Note that this is different from the actor username.
GITHUB_ACTOR_ID: string
// The name of the person or app that initiated the workflow. For example, octocat.
GITHUB_ACTOR: string;
// The path to the file on the runner that contains the full event webhook payload. For example, /github/workflow/event.json.
Expand Down
17 changes: 14 additions & 3 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand, runMain } from "citty";
// import { createRequire } from "module";
import { version } from "./package.json";
import {hash} from 'ohash'
import {hash, objectHash} from 'ohash'
import { Octokit } from "@octokit/action";
import "./environments";

Expand All @@ -10,13 +10,24 @@ if (process.env.GITHUB_ACTIONS !== 'true') {
process.exit(1)
}

const {GITHUB_SERVER_URL, GITHUB_REPOSITORY, GITHUB_RUN_ID, GITHUB_RUN_ATTEMPT, GITHUB_ACTOR_ID} = process.env
const octokit = new Octokit();
const eventPayload = await import(process.env.GITHUB_EVENT_PATH, {
with: { type: "json" },
});

console.log(eventPayload)
console.log(hash(eventPayload))

// Note: If you need to use a workflow run's URL from within a job, you can combine these variables: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
const url = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}`

const token = {
url,
attempt: GITHUB_RUN_ATTEMPT,
actor: GITHUB_ACTOR_ID
}

console.log(token)
console.log(objectHash(token))

// console.log(octokit)
// console.log(eventPayload)
Expand Down

0 comments on commit ae603c0

Please sign in to comment.