Skip to content

Commit

Permalink
Merge branch 'main' into dist-check-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
James M. Greene authored and GitHub committed Aug 5, 2022
2 parents 2fc7b60 + bcfa2c8 commit fcc627b
Show file tree
Hide file tree
Showing 14 changed files with 487 additions and 266 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Set Node.JS
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Setup Node.JS
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'npm'

- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inputs:
description: "GitHub token"
default: ${{ github.token }}
required: true
enablement:
description: "Should a Pages site be enabled for the repository if not so already?"
default: "true"
required: false
outputs:
base_url:
description: 'GitHub Pages site full base URL. Examples: "https://octocat.github.io/my-repo/", "https://octocat.github.io/", "https://www.example.com/"'
Expand Down
202 changes: 121 additions & 81 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14423,6 +14423,104 @@ if (process.env.NODE_DEBUG && /\btunnel\b/.test(process.env.NODE_DEBUG)) {
exports.debug = debug; // for test


/***/ }),

/***/ 9432:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const axios = __nccwpck_require__(6545)
const core = __nccwpck_require__(2186)

function getApiBaseUrl() {
return process.env.GITHUB_API_URL || 'https://api.github.com'
}

async function enablePagesSite({ repositoryNwo, githubToken }) {
const pagesEndpoint = `${getApiBaseUrl()}/repos/${repositoryNwo}/pages`

try {
const response = await axios.post(
pagesEndpoint,
{ build_type: 'workflow' },
{
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${githubToken}`,
'Content-type': 'application/json'
}
}
)

const pageObject = response.data
return pageObject
} catch (error) {
if (error.response && error.response.status === 409) {
return null
}

throw error
}
}

async function getPagesSite({ repositoryNwo, githubToken }) {
try {
const pagesEndpoint = `${getApiBaseUrl()}/repos/${repositoryNwo}/pages`

const response = await axios.get(pagesEndpoint, {
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${githubToken}`
}
})

const pageObject = response.data
return pageObject
} catch (error) {
throw error
}
}

async function findOrCreatePagesSite({ repositoryNwo, githubToken, enablement = true }) {
let pageObject

// Try to find an existing Pages site first
try {
pageObject = await getPagesSite({ repositoryNwo, githubToken })
} catch (error) {
if (!enablement) {
core.error('Get Pages site failed', error)
throw error
}
core.warning('Get Pages site failed', error)
}

if (!pageObject && enablement) {
// Create a new Pages site if one doesn't exist
try {
pageObject = await enablePagesSite({ repositoryNwo, githubToken })
} catch (error) {
core.error('Create Pages site failed', error)
throw error
}

// This somehow implies that the Pages site was already created but initially failed to be retrieved.
// Try one more time for this extreme edge case!
if (pageObject == null) {
try {
pageObject = await getPagesSite({ repositoryNwo, githubToken })
} catch (error) {
core.error('Get Pages site still failed', error)
throw error
}
}
}

return pageObject
}

module.exports = { findOrCreatePagesSite, enablePagesSite, getPagesSite, getApiBaseUrl }


/***/ }),

/***/ 8395:
Expand Down Expand Up @@ -14718,7 +14816,8 @@ function getRequiredVars() {
return {
repositoryNwo: process.env.GITHUB_REPOSITORY,
githubToken: core.getInput('token'),
staticSiteGenerator: core.getInput('static_site_generator')
staticSiteGenerator: core.getInput('static_site_generator'),
enablement: core.getInput('enablement') !== 'false'
}
}

Expand All @@ -14739,85 +14838,19 @@ module.exports = {getContext}

/***/ }),

/***/ 5424:
/***/ 7527:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const core = __nccwpck_require__(2186)
const axios = __nccwpck_require__(6545)

async function enablePages({repositoryNwo, githubToken}) {
const pagesEndpoint = `https://api.github.com/repos/${repositoryNwo}/pages`

try {
const response = await axios.post(
pagesEndpoint,
{build_type: 'workflow'},
{
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${githubToken}`,
'Content-type': 'application/json'
}
}
)
core.info('Created pages site')
} catch (error) {
if (error.response && error.response.status === 409) {
core.info('Pages site exists')
return
}

core.error("Couldn't create pages site", error)
throw error
}
function outputPagesBaseUrl(siteUrl) {
core.setOutput('base_url', siteUrl.href)
core.setOutput('origin', siteUrl.origin)
core.setOutput('host', siteUrl.host)
core.setOutput('base_path', siteUrl.pathname)
}

module.exports = enablePages


/***/ }),

/***/ 9965:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const core = __nccwpck_require__(2186)
const axios = __nccwpck_require__(6545)
const {setPagesPath} = __nccwpck_require__(4770)

async function getPagesBaseUrl({
repositoryNwo,
githubToken,
staticSiteGenerator
}) {
try {
const pagesEndpoint = `https://api.github.com/repos/${repositoryNwo}/pages`

core.info(`Get the Base URL to the page with endpoint ${pagesEndpoint}`)
const response = await axios.get(pagesEndpoint, {
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${githubToken}`
}
})

pageObject = response.data
core.info(JSON.stringify(pageObject))

const siteUrl = new URL(pageObject.html_url)
if (staticSiteGenerator) {
setPagesPath({staticSiteGenerator, path: siteUrl.pathname})
}
core.setOutput('base_url', siteUrl.href)
core.setOutput('origin', siteUrl.origin)
core.setOutput('host', siteUrl.host)
core.setOutput('base_path', siteUrl.pathname)
} catch (error) {
core.error('Get on the Page failed', error)
throw error
}
}

module.exports = getPagesBaseUrl
module.exports = outputPagesBaseUrl


/***/ }),
Expand Down Expand Up @@ -16375,17 +16408,24 @@ var __webpack_exports__ = {};
(() => {
const core = __nccwpck_require__(2186)

const enablePages = __nccwpck_require__(5424)
const getPagesBaseUrl = __nccwpck_require__(9965)

// All variables we need from the runtime are loaded here
const {getContext} = __nccwpck_require__(1319)
const { getContext } = __nccwpck_require__(1319)

const { findOrCreatePagesSite } = __nccwpck_require__(9432)
const { setPagesPath } = __nccwpck_require__(4770)
const outputPagesBaseUrl = __nccwpck_require__(7527)

async function main() {
try {
const context = getContext()
await enablePages(context)
await getPagesBaseUrl(context)
const { repositoryNwo, githubToken, enablement, staticSiteGenerator } = getContext()

const pageObject = await findOrCreatePagesSite({ repositoryNwo, githubToken, enablement })
const siteUrl = new URL(pageObject.html_url)

if (staticSiteGenerator) {
setPagesPath({ staticSiteGenerator, path: siteUrl.pathname })
}
outputPagesBaseUrl(siteUrl)
} catch (error) {
core.setFailed(error)
process.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"private": true,
"name": "configure-pages",
"version": "1.0.0",
"description": "An action to enable Pages and extract various metadata about a site. It can also be used to configure various static site generators we support as starter workflows.",
"main": "src/index.js",
"description": "A GitHub Action to enable Pages and extract various metadata about a site. It can also be used to configure various static site generators we support as starter workflows.",
"main": "./dist/index.js",
"scripts": {
"prepare": "ncc build src/index.js -o dist --source-map --license licenses.txt",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/paper-spa/configure-pages.git"
"url": "git+https://github.com/actions/configure-pages.git"
},
"author": "GitHub",
"license": "MIT",
"bugs": {
"url": "https://github.com/paper-spa/configure-pages/issues"
"url": "https://github.com/actions/configure-pages/issues"
},
"homepage": "https://github.com/paper-spa/configure-pages#readme",
"homepage": "https://github.com/actions/configure-pages#readme",
"dependencies": {
"@actions/core": "^1.8.2",
"axios": "^0.27.2",
Expand Down
Loading

0 comments on commit fcc627b

Please sign in to comment.