Переглянути джерело

chore: create releases via GitHub Actions

Gerald 4 роки тому
батько
коміт
dab0c8b876
7 змінених файлів з 103 додано та 16 видалено
  1. 46 0
      .github/workflows/release.yml
  2. 7 5
      README.md
  3. 1 11
      gulpfile.js
  4. 1 0
      package.json
  5. 24 0
      scripts/action-helper.js
  6. 19 0
      scripts/version-helper.js
  7. 5 0
      yarn.lock

+ 46 - 0
.github/workflows/release.yml

@@ -0,0 +1,46 @@
+name: Release
+
+on:
+  push:
+    tags:
+      - v*
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          persist-credentials: false
+      - uses: actions/setup-node@v2-beta
+        with:
+          node-version: '15'
+      - name: Install deps
+        run: yarn
+      - name: Prepare environment variables
+        run: node scripts/action-helper.js
+      - name: Build
+        run: |
+          yarn build
+          cd dist && zip -r ../$RELEASE_FILENAME.zip .
+      - name: Create Release
+        id: create_release
+        uses: actions/create-release@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          tag_name: ${{ github.ref }}
+          release_name: ${{ env.RELEASE_NAME }}
+          draft: false
+          prerelease: ${{ env.PRERELEASE }}
+          body: ${{ env.RELEASE_NOTE }}
+      - name: Upload Release Asset
+        id: upload-release-asset
+        uses: actions/upload-release-asset@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          upload_url: ${{ steps.create_release.outputs.upload_url }}
+          asset_path: ./${{ env.RELEASE_FILENAME }}.zip
+          asset_name: ${{ env.RELEASE_FILENAME }}.zip
+          asset_content_type: application/zip

+ 7 - 5
README.md

@@ -44,15 +44,17 @@ $ yarn build
 $ yarn build:selfHosted
 ```
 
-### Prerelease
+## Release
 
-```sh
-$ yarn bump
-```
+Just create a tag and push it.
 
-### Release
+When a tag is pushed to GitHub, a (pre)release will be created with assets built by GitHub Actions.
 
 ```sh
+# Create a prerelease
+$ yarn bump
+
+# Create a patch release
 $ yarn version --patch
 ```
 

+ 1 - 11
gulpfile.js

@@ -10,6 +10,7 @@ const Sharp = require('sharp');
 const { isProd } = require('@gera2ld/plaid/util');
 const spawn = require('cross-spawn');
 const i18n = require('./scripts/i18n');
+const { getVersion } = require('./scripts/version-helper');
 const pkg = require('./package.json');
 
 const DIST = 'dist';
@@ -47,17 +48,6 @@ async function jsProd() {
   });
 }
 
-/**
- * Derive extension version from pkg.version and pkg.beta fields.
- *
- * > manifest.version = `${pkg.version}.${pkg.beta}`
- */
-function getVersion() {
-  let version = pkg.version.replace(/-[^.]*/, '');
-  if (pkg.beta) version += `.${pkg.beta}`;
-  return version;
-}
-
 async function readManifest() {
   const input = await fs.readFile(paths.manifest, 'utf8');
   const data = yaml.safeLoad(input);

+ 1 - 0
package.json

@@ -22,6 +22,7 @@
   },
   "description": "Violentmonkey",
   "devDependencies": {
+    "@actions/core": "^1.2.6",
     "@babel/plugin-proposal-function-bind": "^7.8.3",
     "@babel/register": "^7.9.0",
     "@gera2ld/locky": "^0.1.0",

+ 24 - 0
scripts/action-helper.js

@@ -0,0 +1,24 @@
+const core = require('@actions/core');
+const { getVersion, isBeta } = require('./version-helper');
+
+const version = getVersion();
+const beta = isBeta();
+
+core.exportVariable('VERSION', version);
+core.exportVariable('RELEASE_NAME', [
+  beta && 'BETA',
+  `v${version}`,
+].filter(Boolean).join(' '));
+core.exportVariable('RELEASE_FILENAME', [
+  'Violentmonkey',
+  beta && 'beta',
+  `v${version}`,
+].filter(Boolean).join('-'));
+core.exportVariable('PRERELEASE', !!beta);
+
+// TODO generate release notes by conventional commit messages and add installation instructions
+core.exportVariable('RELEASE_NOTE', beta ? `\
+**This is a beta release of Violentmonkey, use it at your own risk.**
+` : `\
+See <https://violentmonkey.github.io/> for more details.
+`);

+ 19 - 0
scripts/version-helper.js

@@ -0,0 +1,19 @@
+const pkg = require('../package.json');
+
+/**
+ * Derive extension version from pkg.version and pkg.beta fields.
+ *
+ * > manifest.version = `${pkg.version}.${pkg.beta}`
+ */
+function getVersion() {
+  let version = pkg.version.replace(/-[^.]*/, '');
+  if (pkg.beta) version += `.${pkg.beta}`;
+  return version;
+}
+
+function isBeta() {
+  return pkg.beta > 0;
+}
+
+exports.getVersion = getVersion;
+exports.isBeta = isBeta;

+ 5 - 0
yarn.lock

@@ -2,6 +2,11 @@
 # yarn lockfile v1
 
 
+"@actions/core@^1.2.6":
+  version "1.2.6"
+  resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.6.tgz#a78d49f41a4def18e88ce47c2cac615d5694bf09"
+  integrity sha1-p41J9BpN7xjojOR8LKxhXVaUvwk=
+
 "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.8.3":
   version "7.8.3"
   resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.8.3.tgz#33e25903d7481181534e12ec0a25f16b6fcf419e"