From c5b7d0d7f33f7c0c1f19802e0eb181cf200b19ef Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Mon, 29 Jan 2018 17:42:12 -0800 Subject: [PATCH] feat(publisher): add snapcraft publisher --- README.md | 8 ++++++++ src/publishers/snapcraft.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/publishers/snapcraft.js diff --git a/README.md b/README.md index 909017daa8..6e150feda4 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,7 @@ the JS file method mentioned above then you can use functions normally. | GitHub Releases - `github` | Makes a new release for the current version (if required) and uploads the make artifacts as release assets | `process.env.GITHUB_TOKEN` - A personal access token with access to your releases
`forge.github_repository.owner` - The owner of the GitHub repository
`forge.github_repository.name` - The name of the GitHub repository
`forge.github_repository.draft` - Create the release as a draft, defaults to `true`
`forge.github_repository.prerelease` - Identify the release as a prerelease, defaults to `false` | | Amazon S3 - `s3` | Uploads your artifacts to the given S3 bucket | `process.env.ELECTRON_FORGE_S3_SECRET_ACCESS_KEY` - Your secret access token for your AWS account _(falls back to the standard `AWS_SECRET_ACCESS_KEY` environment variable)_
`forge.s3.accessKeyId` - Your access key for your AWS account _(falls back to the standard `AWS_ACCESS_KEY_ID` environment variable)_
`forge.s3.bucket` - The name of the S3 bucket to upload to
`forge.s3.folder` - The folder path to upload to inside your bucket, defaults to your application version
`forge.s3.public` - Whether to make the S3 upload public, defaults to `false` | | [Electron Release Server](https://github.com/ArekSredzki/electron-release-server) - `electron-release-server` | Makes a new release for the current version and uploads the artifacts to the correct platform/arch in the given version. If the version already exists no upload will be performed. The channel is determined from the current version. | `forge.electronReleaseServer.baseUrl` - The base URL of your release server, no trailing slash
`forge.electronReleaseServer.username` - The username for the admin panel on your server
`forge.electronReleaseServer.password` - The password for the admin panel on your server | +| [Snapcraft](https://snapcraft.io/store/) - `snapStore` | Uploads generated Snaps to the Snap Store. | `forge.snapStore.release` - If specified, a comma-separated list of channels to release to. | For example: @@ -262,6 +263,13 @@ For example: "password": "no_one_will_guess_this" } } + +// Snap Store +{ + "snapStore": { + "release": "candidate,beta" + } +} ``` ## Custom `make` and `publish` targets diff --git a/src/publishers/snapcraft.js b/src/publishers/snapcraft.js new file mode 100644 index 0000000000..4f4392631a --- /dev/null +++ b/src/publishers/snapcraft.js @@ -0,0 +1,28 @@ +import fs from 'fs-extra'; +import path from 'path'; +import Snapcraft from 'electron-installer-snap/snapcraft'; + +import asyncOra from '../util/ora-handler'; + +/** + * `forgeConfig.snapStore`: + * * `release`: comma-separated list of channels to release to + */ +export default async ({ dir, artifacts, forgeConfig }) => { + const snapArtifacts = artifacts.filter(artifact => artifact.endsWith('.snap')); + + if (snapArtifacts.length === 0) { + throw 'No snap files to upload!'; + } + + const snapcraftCfgPath = path.join(dir, '.snapcraft', 'snapcraft.cfg'); + + if (!await fs.pathExists(snapcraftCfgPath)) { + throw 'Snapcraft config not found!'; + } + + await asyncOra('Pushing snap to the snap store', async () => { + const snapcraft = new Snapcraft(); + await snapcraft.run(dir, 'push', forgeConfig.snapStore, snapArtifacts); + }); +};