Skip to content

Commit 1b1f5de

Browse files
committed
Add code
1 parent fd0d2f6 commit 1b1f5de

File tree

9 files changed

+7337
-0
lines changed

9 files changed

+7337
-0
lines changed

.github/workflows/release.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
name: Build and Upload Artifact
14+
runs-on: ubuntu-latest
15+
outputs:
16+
artifact_name: ${{ steps.rename_artifact.outputs.artifact_name }}
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Run build
30+
run: npm run package
31+
32+
- name: Rename artifact
33+
id: rename_artifact
34+
run: |
35+
if [[ $GITHUB_REF == refs/tags/* ]]; then
36+
tagName=${GITHUB_REF#refs/tags/}
37+
echo "Renaming artifact to extension-$tagName.zip"
38+
mv extension.fplx extension-$tagName.zip
39+
echo "artifact_name=extension-$tagName" >> $GITHUB_OUTPUT
40+
echo "artifact_path=extension-$tagName.zip" >> $GITHUB_OUTPUT
41+
else
42+
commitHash=$(git rev-parse --short "$GITHUB_SHA")
43+
echo "Renaming artifact to extension-$commitHash.zip"
44+
mv extension.fplx extension-$commitHash.zip
45+
echo "artifact_name=extension-$commitHash" >> $GITHUB_OUTPUT
46+
echo "artifact_path=extension-$commitHash.zip" >> $GITHUB_OUTPUT
47+
fi
48+
49+
- name: Upload release artifact
50+
if: ${{ !env.ACT }}
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: ${{ steps.rename_artifact.outputs.artifact_name }}
54+
path: ${{ steps.rename_artifact.outputs.artifact_path }}
55+
56+
release:
57+
name: Create Release
58+
runs-on: ubuntu-latest
59+
needs: build
60+
if: startsWith(github.ref, 'refs/tags/v')
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@v4
64+
65+
- uses: actions/download-artifact@v4
66+
if: ${{ !env.ACT }}
67+
with:
68+
name: ${{ needs.build.outputs.artifact_name }}
69+
70+
- name: Extract changelog entry
71+
id: changelog
72+
run: |
73+
tagName=${GITHUB_REF#refs/tags/}
74+
tagName=${tagName#v}
75+
awk "/## \\[${tagName}\\]/ {flag=1; next} /^## \\[/ {flag=0} flag {print}" CHANGELOG.md > extracted_changelog.md
76+
echo "Extracted changelog:"
77+
cat extracted_changelog.md
78+
echo "tagName=${tagName}" >> $GITHUB_OUTPUT
79+
80+
- name: Release
81+
if: ${{ !env.ACT }}
82+
uses: softprops/action-gh-release@v2
83+
with:
84+
name: "Release ${{ steps.changelog.outputs.tagName }}"
85+
tag_name: "v${{ steps.changelog.outputs.tagName }}"
86+
token: ${{ secrets.GITHUB_TOKEN }}
87+
body_path: extracted_changelog.md
88+
files: extension-*.zip

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/dist
2+
/node_modules
3+
/package
4+
/*.zip
5+
extension.fplx

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - 2024-12-11
9+
10+
### Added
11+
- Inital release

gulpfile.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const { series } = require('gulp');
2+
const fs = require('fs');
3+
const gulp = require('gulp');
4+
const zip = require('gulp-zip');
5+
const webpack = require('webpack');
6+
const merge = require('merge-stream');
7+
const webpackConfig = require('./webpack.config.js')
8+
9+
const filesToCopy = [
10+
'package.json',
11+
'icon.png',
12+
'LICENSE.md',
13+
'README.md'
14+
];
15+
16+
function clean(cb) {
17+
fs.rmdir('./package', { recursive: true }, (err) => {
18+
if (err) { console.log('Clean', err) }
19+
cb();
20+
});
21+
}
22+
23+
function build(cb) {
24+
webpack({...webpackConfig, mode: 'production' }, (err, stats) => {
25+
if (err) { console.log('Webpack', err) }
26+
console.log(stats.toString({ /* stats options */ }))
27+
cb();
28+
});
29+
}
30+
31+
function stage() {
32+
const streams = filesToCopy.map(file => {
33+
if (fs.existsSync(file)) {
34+
return gulp.src(file).pipe(gulp.dest('package/hello-world'));
35+
}
36+
}).filter(s => s != undefined);
37+
return merge([
38+
...streams,
39+
gulp.src('dist/**/*').pipe(gulp.dest('package/hello-world/dist')),
40+
gulp.src('static/**/*').pipe(gulp.dest('package/hello-world/static')),
41+
]);
42+
}
43+
44+
function package() {
45+
return gulp.src('package/**/*').pipe(zip('extension.fplx')).pipe(gulp.dest('.'));
46+
}
47+
48+
exports.clean = clean;
49+
exports.build = build;
50+
exports.stage = stage;
51+
exports.package = package;
52+
exports.default = series(clean, build, stage, package);

0 commit comments

Comments
 (0)