diff --git a/README.md b/README.md index b2a1fa7..a58238f 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ jobs: | `error_count` | `false` | `"10"` | Maximum number of status report errors before cancelling a deployment (default: 10) | | `reporting_interval` | `false` | `"5000"` | Time in milliseconds between two deployment status reports (default: 5 seconds) | | `artifact_name` | `false` | `"github-pages"` | The name of the artifact to deploy | +| `artifact_id` | `false` | | ID of the artifact to deploy (overrides artifact_name if provided) | | `preview` | `false` | `"false"` | Is this attempting to deploy a pull request as a GitHub Pages preview site? (NOTE: This feature is only in alpha currently and is not available to the public!) | ### Outputs 📤 @@ -131,3 +132,9 @@ The scripts and documentation in this project are released under the [MIT Licens [draft-release]: .github/workflows/draft-release.yml [release]: .github/workflows/release.yml [release-workflow-runs]: https://github.com/actions/deploy-pages/actions/workflows/release.yml + +## File Modification Dates + +GitHub Pages deployments will set the modification date of uploaded files to the time of deployment, not the original file's last modified date. This is a limitation of the platform and cannot be changed by this action. + +**Note:** If you provide `artifact_id`, it will be used directly for deployment and as the build version for uniqueness. This is useful if you have multiple artifacts with the same name in your workflow run. diff --git a/action.yml b/action.yml index 1f80766..aacf98f 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,9 @@ inputs: description: 'Name of the artifact to deploy' required: false default: 'github-pages' + artifact_id: + description: 'ID of the artifact to deploy (overrides artifact_name if provided)' + required: false preview: description: 'Is this attempting to deploy a pull request as a GitHub Pages preview site? (NOTE: This feature is only in alpha currently and is not available to the public!)' required: false diff --git a/src/__tests__/internal/deployment.test.js b/src/__tests__/internal/deployment.test.js index 5722742..7e1c333 100644 --- a/src/__tests__/internal/deployment.test.js +++ b/src/__tests__/internal/deployment.test.js @@ -553,6 +553,22 @@ describe('Deployment', () => { ) twirpScope.done() }) + + it('creates deployment using provided artifact_id and uses it as build version', async () => { + process.env.INPUT_ARTIFACT_ID = '1234567890'; + // Set up the mock for the deployment creation + mockPool.intercept({ + path: '/repos/actions/is-awesome/pages/deployments', + method: 'POST', + body: bodyString => { + const body = JSON.parse(bodyString); + return body.artifact_id === '1234567890' && body.pages_build_version === '1234567890'; + } + }).reply(200, { id: '1234567890', status_url: 'https://api.github.com/repos/actions/is-awesome/pages/deployments/1234567890' }, { 'content-type': 'application/json' }); + const deployment = new Deployment(); + await deployment.create(fakeJwt); + delete process.env.INPUT_ARTIFACT_ID; + }) }) describe('#check', () => { diff --git a/src/internal/context.js b/src/internal/context.js index 82c62db..c02f233 100644 --- a/src/internal/context.js +++ b/src/internal/context.js @@ -12,6 +12,7 @@ function getRequiredVars() { githubApiUrl: process.env.GITHUB_API_URL ?? 'https://api.github.com', githubServerUrl: process.env.GITHUB_SERVER_URL ?? 'https://github.com', artifactName: core.getInput('artifact_name') || 'github-pages', + artifactId: core.getInput('artifact_id') || null, isPreview: core.getInput('preview') === 'true' } } diff --git a/src/internal/deployment.js b/src/internal/deployment.js index b140b0c..6940cef 100644 --- a/src/internal/deployment.js +++ b/src/internal/deployment.js @@ -43,6 +43,7 @@ class Deployment { this.isPreview = context.isPreview === true this.timeout = MAX_TIMEOUT this.startTime = null + this.artifactId = context.artifactId } // Call GitHub api to fetch artifacts matching the provided name and deploy to GitHub Pages @@ -62,7 +63,18 @@ class Deployment { core.debug(`Action ID: ${this.actionsId}`) core.debug(`Actions Workflow Run ID: ${this.workflowRun}`) - const artifactData = await getArtifactMetadata({ artifactName: this.artifactName }) + let artifactData = null; + let artifactIdToUse = this.artifactId; + let buildVersionToUse = this.buildVersion; + + if (artifactIdToUse) { + // If artifact_id is provided, use it directly and set buildVersion to artifact_id for uniqueness + buildVersionToUse = artifactIdToUse; + core.info(`Using provided artifact_id: ${artifactIdToUse}`); + } else { + artifactData = await getArtifactMetadata({ artifactName: this.artifactName }); + artifactIdToUse = artifactData.id; + } if (artifactData?.size > ONE_GIGABYTE) { core.warning( @@ -72,8 +84,8 @@ class Deployment { const deployment = await createPagesDeployment({ githubToken: this.githubToken, - artifactId: artifactData.id, - buildVersion: this.buildVersion, + artifactId: artifactIdToUse, + buildVersion: buildVersionToUse, idToken, isPreview: this.isPreview }) @@ -81,13 +93,13 @@ class Deployment { if (deployment) { this.deploymentInfo = { ...deployment, - id: deployment.id || deployment.status_url?.split('/')?.pop() || this.buildVersion, + id: deployment.id || deployment.status_url?.split('/')?.pop() || buildVersionToUse, pending: true } this.startTime = Date.now() } - core.info(`Created deployment for ${this.buildVersion}, ID: ${this.deploymentInfo?.id}`) + core.info(`Created deployment for ${buildVersionToUse}, ID: ${this.deploymentInfo?.id}`) core.debug(JSON.stringify(deployment))