From 08f9edacf8bae7bca19e9be513d5ecfbed75da6c Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sun, 20 Jun 2021 18:35:55 +0800 Subject: [PATCH] chore: add github actions. (halo-dev/console#340) * chore: add github actions. * chore: add github actions. * chore: add github actions. * chore: add github actions. * chore: add github actions. * chore: add github actions. * chore: add github actions. * chore: remove travis ci. * doc: update README.md --- .github/workflows/main.yml | 93 ++++++++++++++++++++++++++++++-------- .travis.yml | 27 ----------- README.md | 2 +- scripts/zip_dist.sh | 6 --- 4 files changed, 74 insertions(+), 54 deletions(-) delete mode 100644 .travis.yml delete mode 100755 scripts/zip_dist.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ddcf7fc1c..4741c4280 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,30 +1,83 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI +name: Halo Admin CI on: - push: - branches: [ master ] pull_request: - branches: [ master ] + paths: + - '**' + - '!**.md' + push: + branches: + - '**' + paths: + - '**' + - '!**.md' + release: + types: + - created jobs: - build: - + check: runs-on: ubuntu-latest strategy: matrix: - node-version: [10.x, 12.x, 14.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - + node-version: [10.x, 12.x, 14.x, 15.x, 16.x] steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm run build --if-present - - run: npm test + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run lint + + github-release: + runs-on: ubuntu-latest + needs: check + if: github.event_name == 'release' + steps: + - uses: actions/checkout@v2 + - name: Use Node.js 14 + uses: actions/setup-node@v2 + with: + node-version: '14' + - run: npm install + - name: Build for release + run: npm run build + - name: Compress dist directory + run: | + PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' package.json) + ARTIFACT_NAME=halo-admin-${PACKAGE_VERSION}.zip + ARTIFACT_PATHNAME=dist/${ARTIFACT_NAME} + + echo "Halo admin version $PACKAGE_VERSION" + echo "Artifact name: ${ARTIFACT_NAME}" + echo "Artifact pathname: ${ARTIFACT_PATHNAME}" + echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV + echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV + echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV + echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV + zip -r $ARTIFACT_PATHNAME dist + + - name: Upload a Release Asset + uses: actions/github-script@v2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const fs = require('fs').promises; + const { repo: { owner, repo }, sha } = context; + console.log({ owner, repo, sha }); + + const releaseId = process.env.RELEASE_ID + const artifactPathName = process.env.ARTIFACT_PATHNAME + const artifactName = process.env.ARTIFACT_NAME + console.log('Releasing', releaseId, artifactPathName, artifactName) + + await github.repos.uploadReleaseAsset({ + owner, repo, + release_id: releaseId, + name: artifactName, + data: await fs.readFile(artifactPathName) + }); + + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d000a0199..000000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: node_js -node_js: stable - -jobs: - include: - - stage: build - script: - - npm run build - - scripts/zip_dist.sh - - ls -la dist - deploy: - provider: releases - api_key: $GITHUB_OAUTH_TOKEN - file_glob: true - file: dist/*.zip - skip_cleanup: true - on: - tags: true -stages: - - build -branches: - only: - - master - - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ - -notifications: - webhooks: https://fathomless-fjord-24024.herokuapp.com/notify \ No newline at end of file diff --git a/README.md b/README.md index 53f44b5a9..44682851b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ npm release GitHub All Releases GitHub last commit -Travis CI +GitHub Workflow Status

------------------------------ diff --git a/scripts/zip_dist.sh b/scripts/zip_dist.sh deleted file mode 100755 index 3cd6cc687..000000000 --- a/scripts/zip_dist.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' package.json) -echo "Halo admin version $PACKAGE_VERSION" -zip -r dist/halo-admin-$PACKAGE_VERSION.zip dist - -export PACKAGE_VERSION \ No newline at end of file