|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + pull_request: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - "alpha" |
| 10 | + |
| 11 | +jobs: |
| 12 | + prepare: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Github Info |
| 17 | + run: | |
| 18 | + echo "GITHUB_ACTION: $GITHUB_ACTION" |
| 19 | + echo "GITHUB_ACTOR: $GITHUB_ACTOR" |
| 20 | + echo "GITHUB_REF: $GITHUB_REF" |
| 21 | + echo "GITHUB_HEAD_REF: $GITHUB_HEAD_REF" |
| 22 | + echo "GITHUB_BASE_REF: $GITHUB_BASE_REF" |
| 23 | + echo "github.event_name: ${{ github.event_name }}" |
| 24 | + cat $GITHUB_EVENT_PATH |
| 25 | +
|
| 26 | + - name: Use Node.js 14.19.3 |
| 27 | + uses: actions/setup-node@v2 |
| 28 | + with: |
| 29 | + node-version: "14.19.3" |
| 30 | + |
| 31 | + - uses: actions/checkout@v2 |
| 32 | + |
| 33 | + - name: Versions |
| 34 | + run: | |
| 35 | + npm --versions |
| 36 | + node -v |
| 37 | + git version |
| 38 | +
|
| 39 | + - name: check package-lock |
| 40 | + run: | |
| 41 | + npx package-lock-check |
| 42 | +
|
| 43 | + - name: Cache node modules |
| 44 | + id: cache-nodemodules |
| 45 | + uses: actions/cache@v2 |
| 46 | + with: |
| 47 | + path: ./node_modules |
| 48 | + key: ${{ runner.OS }}-node_modules-4-${{ hashFiles('./package-lock.json', '.github/workflows/build_and_test.yml') }} |
| 49 | + |
| 50 | + - name: npm install |
| 51 | + if: steps.cache-nodemodules.outputs.cache-hit != 'true' |
| 52 | + run: npm install |
| 53 | + |
| 54 | + - name: Prepare workspace |
| 55 | + run: | |
| 56 | + tar czf /tmp/workspace.tar.gz . |
| 57 | +
|
| 58 | + - uses: actions/upload-artifact@v2 |
| 59 | + with: |
| 60 | + name: workspace |
| 61 | + path: /tmp/workspace.tar.gz |
| 62 | + |
| 63 | + lint: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: prepare |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Use Node.js 14.19.3 |
| 69 | + uses: actions/setup-node@v2 |
| 70 | + with: |
| 71 | + node-version: "14.19.3" |
| 72 | + |
| 73 | + - uses: actions/download-artifact@v2 |
| 74 | + with: |
| 75 | + name: workspace |
| 76 | + path: /tmp |
| 77 | + |
| 78 | + - name: Decompress workspace |
| 79 | + run: | |
| 80 | + tar xzf /tmp/workspace.tar.gz . |
| 81 | +
|
| 82 | + - name: Lint TypeScript Code |
| 83 | + run: npm run lint |
| 84 | + |
| 85 | + test: |
| 86 | + runs-on: ubuntu-latest |
| 87 | + needs: prepare |
| 88 | + |
| 89 | + steps: |
| 90 | + - name: Use Node.js 14.19.3 |
| 91 | + uses: actions/setup-node@v2 |
| 92 | + with: |
| 93 | + node-version: "14.19.3" |
| 94 | + |
| 95 | + - uses: actions/download-artifact@v2 |
| 96 | + with: |
| 97 | + name: workspace |
| 98 | + path: /tmp |
| 99 | + |
| 100 | + - name: Decompress workspace |
| 101 | + run: | |
| 102 | + tar xzf /tmp/workspace.tar.gz . |
| 103 | +
|
| 104 | + - name: Test TypeScript Code |
| 105 | + run: npm run unit-tests |
| 106 | + |
| 107 | + build: |
| 108 | + runs-on: ubuntu-latest |
| 109 | + needs: |
| 110 | + - lint |
| 111 | + - test |
| 112 | + |
| 113 | + steps: |
| 114 | + - name: Use Node.js 14.19.3 |
| 115 | + uses: actions/setup-node@v2 |
| 116 | + with: |
| 117 | + node-version: "14.19.3" |
| 118 | + |
| 119 | + - uses: actions/download-artifact@v2 |
| 120 | + with: |
| 121 | + name: workspace |
| 122 | + path: /tmp |
| 123 | + |
| 124 | + - name: Decompress workspace |
| 125 | + run: | |
| 126 | + tar xzf /tmp/workspace.tar.gz . |
| 127 | +
|
| 128 | + - name: Compile TypeScript into JavaScript |
| 129 | + run: npm run compile |
| 130 | + |
| 131 | + - name: Prepare workspace |
| 132 | + run: | |
| 133 | + tar czf /tmp/workspace.tar.gz . |
| 134 | +
|
| 135 | + - uses: actions/upload-artifact@v2 |
| 136 | + with: |
| 137 | + name: workspace |
| 138 | + path: /tmp/workspace.tar.gz |
| 139 | + |
| 140 | + publish: |
| 141 | + runs-on: ubuntu-latest |
| 142 | + if: github.event_name == 'release' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta' |
| 143 | + needs: build |
| 144 | + |
| 145 | + steps: |
| 146 | + - name: Use Node.js 14.19.3 |
| 147 | + uses: actions/setup-node@v2 |
| 148 | + with: |
| 149 | + node-version: "14.19.3" |
| 150 | + |
| 151 | + - uses: actions/download-artifact@v2 |
| 152 | + with: |
| 153 | + name: workspace |
| 154 | + path: /tmp |
| 155 | + |
| 156 | + - name: Decompress workspace |
| 157 | + run: | |
| 158 | + tar xzf /tmp/workspace.tar.gz . |
| 159 | +
|
| 160 | + - name: Authenticate with registry |
| 161 | + env: |
| 162 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 163 | + run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc |
| 164 | + |
| 165 | + - name: Publish package |
| 166 | + run: | |
| 167 | + if [[ '${{ github.event_name }}' = 'release' ]]; then |
| 168 | + npm publish --tag latest |
| 169 | + else |
| 170 | + ls -la |
| 171 | + # Add build number to the end of the version |
| 172 | + npm version "$(node -p "require('./package.json').version").${{ github.run_number }}" --no-git-tag-version |
| 173 | +
|
| 174 | + GIT_BRANCH="${GITHUB_REF#*heads/}" |
| 175 | + if [[ $GIT_BRANCH == 'alpha' ]]; then |
| 176 | + npm run go-publish-alpha |
| 177 | + else |
| 178 | + npm run go-publish-beta |
| 179 | + fi; |
| 180 | + fi; |
0 commit comments