Skip to content

Commit

Permalink
Add outputs for origin, host, and base_path
Browse files Browse the repository at this point in the history
  • Loading branch information
James M. Greene authored and James M. Greene committed Jun 8, 2022
1 parent 9402878 commit 11f3541
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ inputs:
required: true
outputs:
base_url:
description: 'URL to deployed GitHub Pages'
description: 'GitHub Pages site full base URL. Examples: "https://octocat.github.io/my-repo/", "https://octocat.github.io/", "https://www.example.com/"'
origin:
description: 'GitHub Pages site origin. Examples: "https://octocat.github.io", "https://www.example.com"'
host:
description: 'GitHub Pages site host. Examples: "octocat.github.io", "www.example.com"'
base_path:
description: 'GitHub Pages site full base path. Examples: "/my-repo/" or "/"'
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async function getPageBaseUrl() {

core.info("GITHUB_TOKEN : " + context.githubToken)

core.info(`Get the Base URL to the page with endpoint ${pagesEndpoint}`)
const response = await axios.get(
pagesEndpoint,
{
Expand All @@ -24,8 +25,12 @@ async function getPageBaseUrl() {

pageObject = response.data
core.info(JSON.stringify(pageObject))
core.setOutput('base_url', pageObject.html_url)
core.info(`Get the Base URL to the page with endpoint ${pagesEndpoint}`)

const siteUrl = new URL(pageObject.html_url)
core.setOutput('base_url', siteUrl.href)
core.setOutput('origin', siteUrl.origin)
core.setOutput('host', siteUrl.host)
core.setOutput('base_path', siteUrl.pathname)
} catch (e) {
console.info('Get on the Page failed', e)
process.exit(1)
Expand Down

0 comments on commit 11f3541

Please sign in to comment.