From 13d89854617f6acfb3bc8196d7749bd4861350fa Mon Sep 17 00:00:00 2001 From: Thomas Schoffelen Date: Mon, 31 Dec 2018 19:34:13 +0100 Subject: [PATCH] Added /github/home and /github/workflow/event.json support --- .gitignore | 1 + README.md | 2 - assets/event.json | 136 ++++++++++++++++++++++++++++++++++++++++++++++ lib/utils.js | 16 +++++- 4 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 assets/event.json diff --git a/.gitignore b/.gitignore index eb79dd5..f0a950a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules .idea +.github/main.workflow diff --git a/README.md b/README.md index b928c45..5ba9e15 100644 --- a/README.md +++ b/README.md @@ -46,5 +46,3 @@ Some improvements are also possible in other areas: - [ ] Add support for [secrets](https://developer.github.com/actions/creating-workflows/storing-secrets/) - [ ] Add support for default [`GITHUB_TOKEN`](https://developer.github.com/actions/creating-workflows/storing-secrets/#github-token-secret) env var -- [ ] Add [`/github/home`](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#filesystem) volume that should exist by default -- [ ] Add file [`/github/workflow/event.json`](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#filesystem) that should exist by default diff --git a/assets/event.json b/assets/event.json new file mode 100644 index 0000000..4dbe17c --- /dev/null +++ b/assets/event.json @@ -0,0 +1,136 @@ +{ + "action": "push", + "branch": "master", + "ref": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "repository": { + "id": 17273051, + "node_id": "MDEwOlJlcG9zaXRvcnkxNzI3MzA1MQ==", + "name": "octo-repo", + "full_name": "octo-org/octo-repo", + "private": true, + "owner": { + "login": "octo-org", + "id": 6811672, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjY4MTE2NzI=", + "avatar_url": "https://avatars3.githubusercontent.com/u/6811672?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/octo-org", + "html_url": "https://github.com/octo-org", + "followers_url": "https://api.github.com/users/octo-org/followers", + "following_url": "https://api.github.com/users/octo-org/following{/other_user}", + "gists_url": "https://api.github.com/users/octo-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octo-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octo-org/subscriptions", + "organizations_url": "https://api.github.com/users/octo-org/orgs", + "repos_url": "https://api.github.com/users/octo-org/repos", + "events_url": "https://api.github.com/users/octo-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/octo-org/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/octo-org/octo-repo", + "description": "My first repo on GitHub!", + "fork": false, + "url": "https://api.github.com/repos/octo-org/octo-repo", + "forks_url": "https://api.github.com/repos/octo-org/octo-repo/forks", + "keys_url": "https://api.github.com/repos/octo-org/octo-repo/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/octo-org/octo-repo/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/octo-org/octo-repo/teams", + "hooks_url": "https://api.github.com/repos/octo-org/octo-repo/hooks", + "issue_events_url": "https://api.github.com/repos/octo-org/octo-repo/issues/events{/number}", + "events_url": "https://api.github.com/repos/octo-org/octo-repo/events", + "assignees_url": "https://api.github.com/repos/octo-org/octo-repo/assignees{/user}", + "branches_url": "https://api.github.com/repos/octo-org/octo-repo/branches{/branch}", + "tags_url": "https://api.github.com/repos/octo-org/octo-repo/tags", + "blobs_url": "https://api.github.com/repos/octo-org/octo-repo/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/octo-org/octo-repo/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/octo-org/octo-repo/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/octo-org/octo-repo/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/octo-org/octo-repo/statuses/{sha}", + "languages_url": "https://api.github.com/repos/octo-org/octo-repo/languages", + "stargazers_url": "https://api.github.com/repos/octo-org/octo-repo/stargazers", + "contributors_url": "https://api.github.com/repos/octo-org/octo-repo/contributors", + "subscribers_url": "https://api.github.com/repos/octo-org/octo-repo/subscribers", + "subscription_url": "https://api.github.com/repos/octo-org/octo-repo/subscription", + "commits_url": "https://api.github.com/repos/octo-org/octo-repo/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/octo-org/octo-repo/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/octo-org/octo-repo/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/octo-org/octo-repo/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/octo-org/octo-repo/contents/{+path}", + "compare_url": "https://api.github.com/repos/octo-org/octo-repo/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/octo-org/octo-repo/merges", + "archive_url": "https://api.github.com/repos/octo-org/octo-repo/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/octo-org/octo-repo/downloads", + "issues_url": "https://api.github.com/repos/octo-org/octo-repo/issues{/number}", + "pulls_url": "https://api.github.com/repos/octo-org/octo-repo/pulls{/number}", + "milestones_url": "https://api.github.com/repos/octo-org/octo-repo/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octo-org/octo-repo/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/octo-org/octo-repo/labels{/name}", + "releases_url": "https://api.github.com/repos/octo-org/octo-repo/releases{/id}", + "deployments_url": "https://api.github.com/repos/octo-org/octo-repo/deployments", + "created_at": "2014-02-28T02:42:51Z", + "updated_at": "2018-10-10T15:58:51Z", + "pushed_at": "2018-10-10T15:58:47Z", + "git_url": "git://github.com/octo-org/octo-repo.git", + "ssh_url": "git@github.com:octo-org/octo-repo.git", + "clone_url": "https://github.com/octo-org/octo-repo.git", + "svn_url": "https://github.com/octo-org/octo-repo", + "homepage": "", + "size": 59, + "stargazers_count": 0, + "watchers_count": 0, + "language": "JavaScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 1, + "mirror_url": null, + "archived": false, + "open_issues_count": 23, + "license": null, + "forks": 1, + "open_issues": 23, + "watchers": 0, + "default_branch": "master" + }, + "organization": { + "login": "octo-org", + "id": 6811672, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjY4MTE2NzI=", + "url": "https://api.github.com/orgs/octo-org", + "repos_url": "https://api.github.com/orgs/octo-org/repos", + "events_url": "https://api.github.com/orgs/octo-org/events", + "hooks_url": "https://api.github.com/orgs/octo-org/hooks", + "issues_url": "https://api.github.com/orgs/octo-org/issues", + "members_url": "https://api.github.com/orgs/octo-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/octo-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/6811672?v=4", + "description": "Working better together!" + }, + "sender": { + "login": "Codertocat", + "id": 21031067, + "node_id": "MDQ6VXNlcjIxMDMxMDY3", + "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Codertocat", + "html_url": "https://github.com/Codertocat", + "followers_url": "https://api.github.com/users/Codertocat/followers", + "following_url": "https://api.github.com/users/Codertocat/following{/other_user}", + "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", + "organizations_url": "https://api.github.com/users/Codertocat/orgs", + "repos_url": "https://api.github.com/users/Codertocat/repos", + "events_url": "https://api.github.com/users/Codertocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "installation": { + "id": 375706, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMzc1NzA2" + } +} diff --git a/lib/utils.js b/lib/utils.js index 73d53bb..273bc6a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -95,9 +95,9 @@ const resolveRunner = (uses) => { const defaultEnv = (action, event) => { return { - GITHUB_ACTOR: 'octocat', + GITHUB_ACTOR: 'Codertocat', HOME: '/github/home', - GITHUB_REPOSITORY: 'github/example', + GITHUB_REPOSITORY: 'octo-org/octo-repo', GITHUB_EVENT_NAME: event, GITHUB_EVENT_PATH: '/github/workflow/event.json', GITHUB_WORKSPACE: '/github/workspace', @@ -139,7 +139,17 @@ const runAction = (actionTitle, actions, event) => { after = action.args } - const cmd = `docker run --rm -t -v \`pwd\`:/github/workspace -w /github/workspace ${args.join(' ')} ${imageName} ${after}` + const assetPath = path.resolve(path.join(__dirname, '..', 'assets', 'event.json')) + + const cmd = [ + `docker run`, + `--rm -t`, + `-v \`pwd\`:/github/workspace`, + `-v /tmp/gh-home:/github/home`, + `-v ${assetPath}:/github/workflow/event.json:ro`, + `-w /github/workspace`, + `${args.join(' ')} ${imageName} ${after}` + ].join(' ') const res = exec(cmd) if (res.code === 0) {