From dfd9d8a36e4d9a15b169ec858773010e7ca05ca7 Mon Sep 17 00:00:00 2001 From: pastdue <30942300+past-due@users.noreply.github.com> Date: Wed, 28 Sep 2022 12:56:57 -0400 Subject: [PATCH] flatpak-builder: Add 'upload-artifact' and 'artifact-name' inputs --- README.md | 2 ++ flatpak-builder/action.yml | 11 +++++++++++ flatpak-builder/index.js | 29 ++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index de188f8e..55b68051 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ jobs: | `cache-key` | Specifies the cache key. CPU arch is automatically added, so there is no need to add it to the cache key. | Optional | `flatpak-builder-${sha256(manifestPath)}` | | `arch` | Specifies the CPU architecture to build for | Optional | `x86_64` | | `mirror-screenshots-url` | Specifies the URL to mirror screenshots | Optional | - | +| `upload-artifact` | Enable/Disable uploading the `.flatpak` as a GitHub Actions artifact | Optional | `true` | +| `artifact-name` | The GitHub Actions artifact name | Optional | `${bundle}-${arch}` | #### Building for multiple CPU architectures diff --git a/flatpak-builder/action.yml b/flatpak-builder/action.yml index e45532aa..2c976f87 100644 --- a/flatpak-builder/action.yml +++ b/flatpak-builder/action.yml @@ -54,6 +54,17 @@ inputs: description: > The URL to mirror screenshots. required: false + upload-artifact: + description: > + Toggles uploading the .flatpak as a GitHub Actions artifact. + Possible values: true, enabled, yes, y. Or something else to disable it. + default: "true" + required: false + artifact-name: + description: > + The name to use when uploading a GitHub Actions artifact. + Defaults to ${bundle}-${arch} + required: false runs: using: "node12" main: "dist/index.js" diff --git a/flatpak-builder/index.js b/flatpak-builder/index.js index 17451a25..f2d5a08b 100644 --- a/flatpak-builder/index.js +++ b/flatpak-builder/index.js @@ -243,6 +243,8 @@ const prepareBuild = async (repositoryName, repositoryUrl, manifestPath, cacheBu * @param {string} cacheKey the default cache key if there are any * @param {string} arch The CPU architecture to build for * @param {string} mirrorScreenshotsUrl The URL to mirror screenshots + * @param {boolean} uploadArtifact Whether to upload the .flatpak as an artifact to GitHub Actions + * @param {string} artifactName The artifact name */ const run = async ( manifestPath, @@ -255,7 +257,9 @@ const run = async ( cacheBuildDir, cacheKey, arch, - mirrorScreenshotsUrl + mirrorScreenshotsUrl, + uploadArtifact, + artifactName ) => { try { cacheKey = await prepareBuild(repositoryName, repositoryUrl, manifestPath, cacheBuildDir, cacheKey, arch) @@ -273,14 +277,19 @@ const run = async ( return build(manifest, modifiedManifestPath, bundle, repositoryUrl, repositoryName, buildDir, localRepoName, cacheBuildDir, cacheKey, arch, mirrorScreenshotsUrl) }) .then(() => { - core.info('Uploading artifact...') - const artifactClient = artifact.create() + if (uploadArtifact) { + core.info('Uploading artifact...') + const artifactClient = artifact.create() - // Append the arch to the bundle name to prevent conflicts in multi-arch jobs - const bundleName = bundle.replace('.flatpak', '') + `-${arch}` - return artifactClient.uploadArtifact(bundleName, [bundle], '.', { - continueOnError: false - }) + // Use the supplied artifactName, + // or append the arch to the bundle name to prevent conflicts in multi-arch jobs + const bundleName = artifactName || bundle.replace('.flatpak', '') + `-${arch}` + return artifactClient.uploadArtifact(bundleName, [bundle], '.', { + continueOnError: false + }) + } else { + core.info('Skipping artifact upload') + } }) .catch((error) => { core.setFailed(`Build failed: ${error}`) @@ -308,6 +317,8 @@ if (require.main === module) { ['y', 'yes', 'true', 'enabled', true].includes(core.getInput('cache')), core.getInput('cache-key'), core.getInput('arch'), - core.getInput('mirror-screenshots-url') + core.getInput('mirror-screenshots-url'), + ['y', 'yes', 'true', 'enabled', true].includes(core.getInput('upload-artifact')), + core.getInput('artifact-name') ) }