|
| 1 | +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node |
| 2 | +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions |
| 3 | + |
| 4 | +name: Node.js CI |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + tags: |
| 11 | + - '*' |
| 12 | + |
| 13 | + pull_request: |
| 14 | + branches: |
| 15 | + - master |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + node-version: [12.x, 14.x] |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checking out for ${{ github.ref }} |
| 27 | + uses: actions/checkout@v2 |
| 28 | + |
| 29 | + - name: Use Node.js ${{ matrix.node-version }} |
| 30 | + uses: actions/setup-node@v1 |
| 31 | + with: |
| 32 | + node-version: ${{ matrix.node-version }} |
| 33 | + |
| 34 | + - name: Run npx version-from-git --no-git-tag-version |
| 35 | + if: ${{ startsWith(github.ref, 'refs/heads/') }} |
| 36 | + run: | |
| 37 | + cd packages/component |
| 38 | + npx version-from-git --no-git-tag-version |
| 39 | +
|
| 40 | + - run: npm ci |
| 41 | + |
| 42 | + - run: npm run bootstrap |
| 43 | + |
| 44 | + - name: Propagate versions |
| 45 | + run: | |
| 46 | + node_modules/.bin/lerna version --force-publish --no-git-tag-version --no-push --yes `cat package.json | jq -r .version` |
| 47 | +
|
| 48 | + - run: npm run build --if-present |
| 49 | + |
| 50 | + - run: npm test |
| 51 | + |
| 52 | + - name: Copy documents |
| 53 | + run: | |
| 54 | + cp CHANGELOG.md packages/component |
| 55 | + cp LICENSE packages/component |
| 56 | + cp README.md packages/component |
| 57 | +
|
| 58 | + - name: Run npm pack |
| 59 | + run: | |
| 60 | + cd packages/component |
| 61 | + npm pack |
| 62 | +
|
| 63 | + - name: Upload npm-tarball |
| 64 | + uses: actions/upload-artifact@v2 |
| 65 | + if: ${{ matrix.node-version == '14.x' }} |
| 66 | + with: |
| 67 | + name: npm-tarball |
| 68 | + path: 'packages/component/*.tgz' |
| 69 | + |
| 70 | + - name: Upload gh-pages |
| 71 | + uses: actions/upload-artifact@v2 |
| 72 | + if: ${{ matrix.node-version == '14.x' }} |
| 73 | + with: |
| 74 | + name: gh-pages |
| 75 | + path: 'packages/playground/build/**/*' |
| 76 | + |
| 77 | + publish: |
| 78 | + needs: build |
| 79 | + runs-on: ubuntu-latest |
| 80 | + if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} |
| 81 | + |
| 82 | + steps: |
| 83 | + - name: Download npm-tarball |
| 84 | + uses: actions/download-artifact@v2 |
| 85 | + with: |
| 86 | + name: npm-tarball |
| 87 | + |
| 88 | + - name: Download gh-pages |
| 89 | + uses: actions/download-artifact@v2 |
| 90 | + with: |
| 91 | + name: gh-pages |
| 92 | + path: gh-pages/ |
| 93 | + |
| 94 | + - name: Read package.json |
| 95 | + id: read-package-json |
| 96 | + run: | |
| 97 | + echo "::set-output name=name::$(tar xOf *.tgz package/package.json | jq -r '.name')" |
| 98 | + echo "::set-output name=version::$(tar xOf *.tgz package/package.json | jq -r '.version')" |
| 99 | + echo "::set-output name=tarball::$(ls *.tgz)" |
| 100 | + echo "::set-output name=date::$(date +%Y-%m-%d)" |
| 101 | +
|
| 102 | + - name: Run npm publish ${{ steps.read-package-json.outputs.name }}@${{ steps.read-package-json.outputs.version }} |
| 103 | + run: | |
| 104 | + npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} |
| 105 | + npm publish *.tgz --tag master |
| 106 | +
|
| 107 | + - name: Run npm dist-tag add ${{ steps.read-package-json.outputs.name }}@${{ steps.read-package-json.outputs.version }} latest |
| 108 | + if: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 109 | + run: | |
| 110 | + npm dist-tag add ${{ steps.read-package-json.outputs.name }}@${{ steps.read-package-json.outputs.version }} latest |
| 111 | +
|
| 112 | + - name: Draft a new release |
| 113 | + uses: actions/create-release@v1 |
| 114 | + id: create-release |
| 115 | + if: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 116 | + env: |
| 117 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + with: |
| 119 | + tag_name: ${{ github.ref }} |
| 120 | + release_name: '[${{ steps.read-package-json.outputs.version }}] - ${{ steps.read-package-json.outputs.date }}' |
| 121 | + draft: true |
| 122 | + |
| 123 | + - name: Upload tarball to release |
| 124 | + uses: actions/upload-release-asset@v1 |
| 125 | + if: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 126 | + env: |
| 127 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + with: |
| 129 | + upload_url: ${{ steps.create-release.outputs.upload_url }} |
| 130 | + asset_path: ./${{ steps.read-package-json.outputs.tarball }} |
| 131 | + asset_name: ${{ steps.read-package-json.outputs.tarball }} |
| 132 | + asset_content_type: application/octet-stream |
| 133 | + |
| 134 | + - name: Deploy to GitHub Pages |
| 135 | + uses: peaceiris/actions-gh-pages@v3 |
| 136 | + with: |
| 137 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 138 | + publish_dir: ./gh-pages/ |
0 commit comments