From 0f2d500b16f976bf12a9000693912c1247bd9620 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sun, 20 Jun 2021 16:05:50 +0800 Subject: [PATCH] chore: add github actions. --- .github/workflows/main.yml | 53 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fb0565ea0..81d01b7fc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,8 +25,57 @@ jobs: steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - - run: npm run lint \ No newline at end of file + - 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' + - 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 + 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) + }); + +