Skip to content

Commit

Permalink
ci: split build and release
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 9, 2022
1 parent f9484f9 commit 2e7bc5f
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 69 deletions.
74 changes: 6 additions & 68 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,7 @@ on:
- main

jobs:
changelog:
name: Create release changelog
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Generate changelog
if: startsWith(github.ref, 'refs/tags/')
run: npx changelogithub # or [email protected] if ensure the stable result
env:
GITHUB_TOKEN: ${{secrets.MY_TOKEN}}

build:
needs: changelog
strategy:
matrix:
platform: [ubuntu-latest]
Expand All @@ -46,73 +30,27 @@ jobs:
uses: actions/checkout@v2
with:
ref: main
path: alist-web
persist-credentials: false
fetch-depth: 0
submodules: recursive

- name: Checkout dist repo
uses: actions/checkout@v2
with:
repository: alist-org/web-dist
ref: main
path: web-dist
persist-credentials: false
fetch-depth: 0

- name: Replace version
if: startsWith(github.ref, 'refs/tags/')
run: |
version=$(git describe --abbrev=0 --tags)
sed -i -e "s/0.0.0/$version/g" alist-web/package.json
- name: Build
run: |
cd alist-web
pnpm install
pnpm i18n
pnpm build
cp -r dist ../
cd ..
env:
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

- name: Copy dist and commit
run: |
cd web-dist
rm -rf dist
cp -r ../dist .
git add .
git config --local user.email "[email protected]"
git config --local user.name "Noah Hsu"
git commit --allow-empty -m "upload dist files" -a
cd ..
- name: Upload dist files
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.MY_TOKEN }}
branch: main
directory: web-dist
repository: alist-org/web-dist

- name: Publish npm
if: startsWith(github.ref, 'refs/tags/')
run: |
cd alist-web
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
pnpm publish --no-git-checks
cd ..
- name: Compress dist files
if: startsWith(github.ref, 'refs/tags/')
- name: Compress dist
run: |
mkdir compress
tar -czvf compress/dist.tar.gz dist/*
zip -r compress/dist.zip dist/*
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
files: compress/*
name: alist-web
path: compress
91 changes: 91 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: release

on:
push:
tags:
- '*'


jobs:
changelog:
name: Create release changelog
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Generate changelog
run: npx changelogithub # or [email protected] if ensure the stable result
env:
GITHUB_TOKEN: ${{secrets.MY_TOKEN}}

release:
needs: changelog
strategy:
matrix:
platform: [ubuntu-latest]
name: Release
runs-on: ${{ matrix.platform }}
steps:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: "16"
registry-url: "https://registry.npmjs.org"

- uses: pnpm/[email protected]
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false

- name: Checkout
uses: actions/checkout@v2
with:
ref: main
path: alist-web
persist-credentials: false
fetch-depth: 0
submodules: recursive

- name: Checkout dist repo
uses: actions/checkout@v2
with:
repository: alist-org/web-dist
ref: main
path: web-dist
persist-credentials: false
fetch-depth: 0

- name: Build
run: |
mv alist-web/release.sh .
bash release.sh
env:
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

- name: Publish npm
run: |
cd alist-web
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
pnpm publish --no-git-checks
cd ..
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Upload dist files
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.MY_TOKEN }}
branch: main
directory: web-dist
repository: alist-org/web-dist

- name: Release
uses: softprops/action-gh-release@v1
with:
files: compress/*
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"name": "alist-web",
"version": "0.0.0",
"description": "",
"author": {
"name": "Xhofe",
"email": "[email protected]",
"url": "https://www.nn.ci"
},
"description": "The front end of Alist V3",
"repository": {
"type": "git",
"url": "git+https://github.com/alist-org/alist-web.git"
},
"bugs": {
"url": "https://github.com/Xhofe/alist/issues"
},
"files": [
"dist"
],
"homepage": "https://alist.nn.ci",
"scripts": {
"crowdin": "crowdin download",
"i18n": "pnpm crowdin -b main --verbose && node ./scripts/i18n.mjs",
Expand Down
27 changes: 27 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# replace version
cd alist-web
version=$(git describe --abbrev=0 --tags)
sed -i -e "s/0.0.0/$version/g" package.json
cat package.json

# build
pnpm install
pnpm i18n
pnpm build
cp -r dist ../
cd ..

# commit to web-dist
cd web-dist
rm -rf dist
cp -r ../dist .
git add .
git config --local user.email "[email protected]"
git config --local user.name "Noah Hsu"
git commit --allow-empty -m "upload $version dist files" -a
git tag -a $version -m "release $version"
cd ..

mkdir compress
tar -czvf compress/dist.tar.gz dist/*
zip -r compress/dist.zip dist/*

0 comments on commit 2e7bc5f

Please sign in to comment.