Skip to content

Commit

Permalink
chore: add github actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Jun 20, 2021
1 parent 1d5a904 commit 0f2d500
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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)
});

0 comments on commit 0f2d500

Please sign in to comment.