|
| 1 | +# DO NOT EDIT: BEGIN |
| 2 | +# This snippet has been inserted automatically by mobsuccessbot, do not edit! |
| 3 | +# If changes are needed, update the action npm in |
| 4 | +# https://github.com/mobsuccess-devops/github-mobsuccess-policy |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [master, preprod, prod] |
| 8 | + pull_request: |
| 9 | + types: [opened, synchronize, reopened] |
| 10 | +name: NPM |
| 11 | +jobs: |
| 12 | + packagejsonlint: |
| 13 | + name: PackageJsonLint |
| 14 | + runs-on: ubuntu-20.04 |
| 15 | + timeout-minutes: 1 |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v3 |
| 18 | + - uses: mobsuccess-devops/github-actions-packagejsonlint@master |
| 19 | + prettier: |
| 20 | + name: Prettier |
| 21 | + runs-on: ubuntu-20.04 |
| 22 | + timeout-minutes: 7 |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v3 |
| 25 | + - uses: actions/setup-node@v3 |
| 26 | + with: |
| 27 | + node-version: 16.16.0 |
| 28 | + - name: Cache Node Modules |
| 29 | + id: cache |
| 30 | + uses: actions/cache@v2 |
| 31 | + env: |
| 32 | + cache-name: cache-node-modules |
| 33 | + with: |
| 34 | + path: ./node_modules |
| 35 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-16.16.0 |
| 36 | + - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc |
| 37 | + name: Configure Credentials For GitHub Packages |
| 38 | + - run: npm ci |
| 39 | + if: steps.cache.outputs.cache-hit != 'true' |
| 40 | + working-directory: . |
| 41 | + - run: npm run prettier |
| 42 | + working-directory: . |
| 43 | + eslint: |
| 44 | + name: Eslint |
| 45 | + runs-on: ubuntu-20.04 |
| 46 | + timeout-minutes: 7 |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v3 |
| 49 | + - uses: actions/setup-node@v3 |
| 50 | + with: |
| 51 | + node-version: 16.16.0 |
| 52 | + - name: Cache Node Modules |
| 53 | + id: cache |
| 54 | + uses: actions/cache@v2 |
| 55 | + env: |
| 56 | + cache-name: cache-node-modules |
| 57 | + with: |
| 58 | + path: ./node_modules |
| 59 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-16.16.0 |
| 60 | + - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc |
| 61 | + name: Configure Credentials For GitHub Packages |
| 62 | + - run: npm ci |
| 63 | + if: steps.cache.outputs.cache-hit != 'true' |
| 64 | + working-directory: . |
| 65 | + - run: npm run eslint |
| 66 | + working-directory: . |
| 67 | + test: |
| 68 | + name: Test |
| 69 | + runs-on: ubuntu-20.04 |
| 70 | + timeout-minutes: 7 |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v3 |
| 73 | + - uses: actions/setup-node@v3 |
| 74 | + with: |
| 75 | + node-version: 16.16.0 |
| 76 | + - name: Cache Node Modules |
| 77 | + id: cache |
| 78 | + uses: actions/cache@v2 |
| 79 | + env: |
| 80 | + cache-name: cache-node-modules |
| 81 | + with: |
| 82 | + path: ./node_modules |
| 83 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-16.16.0 |
| 84 | + - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc |
| 85 | + name: Configure Credentials For GitHub Packages |
| 86 | + - run: npm ci |
| 87 | + if: steps.cache.outputs.cache-hit != 'true' |
| 88 | + working-directory: . |
| 89 | + - run: npm run test |
| 90 | + working-directory: . |
| 91 | + postBuild: |
| 92 | + needs: [packagejsonlint, prettier, eslint, test] |
| 93 | + name: Post-Build |
| 94 | + runs-on: ubuntu-20.04 |
| 95 | + timeout-minutes: 2 |
| 96 | + outputs: |
| 97 | + needsPackage: ${{ steps.checkEligibility.outputs.needsPackage }} |
| 98 | + pr: ${{ steps.checkEligibility.outputs.pr }} |
| 99 | + tag: ${{ steps.checkEligibility.outputs.tag }} |
| 100 | + steps: |
| 101 | + - name: Check Package Eligibility |
| 102 | + id: checkEligibility |
| 103 | + run: | |
| 104 | + if [[ ${{github.ref}} == "refs/heads/master" ]]; then |
| 105 | + echo Packaging for master |
| 106 | + echo "needsPackage=true" >> $GITHUB_OUTPUT |
| 107 | + echo "tag=latest" >> $GITHUB_OUTPUT |
| 108 | + else |
| 109 | + has_label_package=${{ contains(github.event.pull_request.labels.*.name, 'npm-publish') }} |
| 110 | + if [ "$has_label_package" == true ]; then |
| 111 | + echo PR has package label |
| 112 | + pr_number=${{github.event.number}} |
| 113 | + if [ -z "$pr_number" ]; then |
| 114 | + pr_number=${{github.event.issue.number}} |
| 115 | + fi |
| 116 | + echo "needsPackage=true" >> $GITHUB_OUTPUT |
| 117 | + echo "pr=$pr_number" >> $GITHUB_OUTPUT |
| 118 | + echo "tag=pr-$pr_number" >> $GITHUB_OUTPUT |
| 119 | + else |
| 120 | + echo PR does not have package label |
| 121 | + echo "needsPackage=false" >> $GITHUB_OUTPUT |
| 122 | + fi |
| 123 | + fi |
| 124 | +
|
| 125 | + package: |
| 126 | + needs: [postBuild] |
| 127 | + name: Package |
| 128 | + runs-on: ubuntu-20.04 |
| 129 | + timeout-minutes: 2 |
| 130 | + outputs: |
| 131 | + packageVersion: ${{ steps.outputPackageVersion.outputs.packageVersion }} |
| 132 | + if: needs.postBuild.outputs.needsPackage == 'true' |
| 133 | + steps: |
| 134 | + - uses: actions/checkout@v3 |
| 135 | + - uses: actions/setup-node@v3 |
| 136 | + with: |
| 137 | + node-version: 16.16.0 |
| 138 | + - name: Cache Node Modules |
| 139 | + id: cache |
| 140 | + uses: actions/cache@v2 |
| 141 | + env: |
| 142 | + cache-name: cache-node-modules |
| 143 | + with: |
| 144 | + path: ./node_modules |
| 145 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-16.16.0 |
| 146 | + - run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc |
| 147 | + name: Configure Credentials For GitHub Packages |
| 148 | + - run: npm ci |
| 149 | + if: steps.cache.outputs.cache-hit != 'true' |
| 150 | + working-directory: . |
| 151 | + - run: npm version --no-git-tag-version $(node -e 'x=JSON.parse(require("fs").readFileSync("package.json", {encoding:"utf-8"})).version.split("."); x[2]="'$GITHUB_RUN_ID'"; console.log(x.join("."))' ) |
| 152 | + - run: npm version prerelease --no-git-tag-version --preid=pr-${{needs.postBuild.outputs.pr}} |
| 153 | + if: github.ref != 'refs/heads/master' |
| 154 | + - run: echo "packageVersion=$(node -e 'x=JSON.parse(require("fs").readFileSync("package.json", {encoding:"utf-8"})).version; console.log(x)')" >> $GITHUB_OUTPUT |
| 155 | + id: outputPackageVersion |
| 156 | + - name: Push tag |
| 157 | + uses: rickstaa/action-create-tag@v1 |
| 158 | + if: github.ref == 'refs/heads/master' |
| 159 | + with: |
| 160 | + tag: "${{steps.outputPackageVersion.outputs.packageVersion}}" |
| 161 | + force_push_tag: true |
| 162 | + - name: "✏️ Generate release changelog" |
| 163 | + id: build_changelog |
| 164 | + uses: mobsuccess-devops/github-actions-mobsuccess@master |
| 165 | + with: |
| 166 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 167 | + action: "changelog" |
| 168 | + unreleased-tag: ${{ github.ref == 'refs/heads/master' && steps.outputPackageVersion.outputs.packageVersion || ''}} |
| 169 | + max-releases: 10 |
| 170 | + - run: | |
| 171 | + firstLine=$(cat << EOF |
| 172 | + # Changelog |
| 173 | +
|
| 174 | + ## Work In Progress |
| 175 | +
|
| 176 | + [pr-${{needs.postBuild.outputs.pr}}](https://github.com/$GITHUB_REPOSITORY/pull/${{needs.postBuild.outputs.pr}}) |
| 177 | +
|
| 178 | + --- |
| 179 | +
|
| 180 | + EOF |
| 181 | + ) |
| 182 | + echo "$firstLine<br><br>${{ steps.build_changelog.outputs.changelog }}<br><br>-------<br><br>" | cat - README.md > temp && mv temp README.md |
| 183 | + if: github.ref != 'refs/heads/master' |
| 184 | + - run: echo "${{ steps.build_changelog.outputs.changelog }}<br><br>-------<br><br>" | cat - README.md > temp && mv temp README.md |
| 185 | + if: github.ref == 'refs/heads/master' |
| 186 | + - run: npm pack |
| 187 | + working-directory: . |
| 188 | + - name: Upload |
| 189 | + uses: actions/upload-artifact@v2 |
| 190 | + with: |
| 191 | + name: package |
| 192 | + path: "*.tgz" |
| 193 | + publish: |
| 194 | + name: "Publish to GitHub Packages" |
| 195 | + needs: [postBuild, package] |
| 196 | + runs-on: ubuntu-20.04 |
| 197 | + timeout-minutes: 2 |
| 198 | + if: needs.postBuild.outputs.needsPackage == 'true' |
| 199 | + steps: |
| 200 | + - uses: actions/checkout@v3 |
| 201 | + - name: Upload |
| 202 | + uses: actions/download-artifact@v2 |
| 203 | + with: |
| 204 | + name: package |
| 205 | + - uses: actions/setup-node@v3 |
| 206 | + with: |
| 207 | + node-version: 16.16.0 |
| 208 | + registry-url: https://npm.pkg.github.com/ |
| 209 | + scope: "@mobsuccess-devops" |
| 210 | + - run: echo "registry=https://npm.pkg.github.com/@mobsuccess-devops" >> .npmrc |
| 211 | + - run: npm publish $(ls *.tgz) --tag ${{needs.postBuild.outputs.tag}} |
| 212 | + env: |
| 213 | + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 214 | + - name: Create a GitHub release |
| 215 | + uses: ncipollo/release-action@v1 |
| 216 | + if: github.ref == 'refs/heads/master' |
| 217 | + with: |
| 218 | + tag: ${{ needs.package.outputs.packageVersion }} |
| 219 | + prerelease: ${{github.ref != 'refs/heads/master'}} |
| 220 | + generateReleaseNotes: true |
| 221 | +# DO NOT EDIT: END |
0 commit comments