|
| 1 | +# master only |
| 2 | + |
| 3 | +name: Integrate |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [master] |
| 8 | + |
| 9 | +env: |
| 10 | + FORCE_COLOR: 1 |
| 11 | + |
| 12 | +jobs: |
| 13 | + validate: |
| 14 | + name: Validate |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} |
| 18 | + steps: |
| 19 | + - name: Resolve last validated commit hash (for `git diff` purposes) |
| 20 | + env: |
| 21 | + # See https://github.com/serverlessinc/setup-cicd-resources |
| 22 | + GET_LAST_VALIDATED_COMMIT_HASH_URL: ${{ secrets.GET_LAST_VALIDATED_COMMIT_HASH_URL }} |
| 23 | + PUT_LAST_VALIDATED_COMMIT_HASH_URL: ${{ secrets.PUT_LAST_VALIDATED_COMMIT_HASH_URL }} |
| 24 | + run: | |
| 25 | + curl -f "$GET_LAST_VALIDATED_COMMIT_HASH_URL" -o /home/runner/last-validated-commit-hash || : |
| 26 | + curl -v -X PUT -H "User-Agent:" -H "Accept:" -H "Content-Type:" -d "$GITHUB_SHA" "$PUT_LAST_VALIDATED_COMMIT_HASH_URL" |
| 27 | + - name: Store last validated commit hash (as it's to be used in other job) |
| 28 | + uses: actions/upload-artifact@v2 |
| 29 | + with: |
| 30 | + name: last-validated-commit-hash |
| 31 | + path: /home/runner/last-validated-commit-hash |
| 32 | + |
| 33 | + - name: Checkout repository |
| 34 | + uses: actions/checkout@v2 |
| 35 | + |
| 36 | + - name: Retrieve ~/.npm from cache |
| 37 | + uses: actions/cache@v1 |
| 38 | + with: |
| 39 | + path: ~/.npm |
| 40 | + key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('**package*.json') }} |
| 41 | + restore-keys: npm-v14-${{ runner.os }}-${{ github.ref }}- |
| 42 | + - name: Retrieve node_modules from cache |
| 43 | + id: cacheNodeModules |
| 44 | + uses: actions/cache@v1 |
| 45 | + with: |
| 46 | + path: node_modules |
| 47 | + key: node-modules-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} |
| 48 | + restore-keys: node-modules-v14-${{ runner.os }}-${{ github.ref }}- |
| 49 | + - name: Retrieve src/node_modules from cache |
| 50 | + id: cacheSrcNodeModules |
| 51 | + uses: actions/cache@v1 |
| 52 | + with: |
| 53 | + path: src/node_modules |
| 54 | + key: src/node-modules-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('src/package*.json') }} |
| 55 | + restore-keys: src/node-modules-v14-${{ runner.os }}-${{ github.ref }}- |
| 56 | + |
| 57 | + - name: Install Node.js and npm |
| 58 | + uses: actions/setup-node@v1 |
| 59 | + with: |
| 60 | + node-version: 14.x |
| 61 | + |
| 62 | + - name: Install root dependencies |
| 63 | + if: steps.cacheNodeModules.outputs.cache-hit != 'true' |
| 64 | + run: npm update --save-dev --no-save |
| 65 | + - name: Install src dependencies |
| 66 | + if: steps.cacheSrcNodeModules.outputs.cache-hit != 'true' |
| 67 | + run: | |
| 68 | + cd src |
| 69 | + npm ci |
| 70 | +
|
| 71 | + # Ensure no parallel runs |
| 72 | + # See: https://github.community/t/how-to-limit-concurrent-workflow-runs/16844/21 |
| 73 | + - name: Turnstyle |
| 74 | + uses: softprops/turnstyle@v1 |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Publish "dev" version |
| 79 | + run: npm run publish:dev |
| 80 | + |
| 81 | + - name: Integration tests |
| 82 | + env: |
| 83 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 84 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 85 | + run: npm test |
| 86 | + |
| 87 | + tagIfNewVersion: |
| 88 | + name: Tag if new version |
| 89 | + runs-on: ubuntu-latest |
| 90 | + needs: validate |
| 91 | + steps: |
| 92 | + - name: Checkout repository |
| 93 | + uses: actions/checkout@v2 |
| 94 | + with: |
| 95 | + # Ensure to have complete history of commits pushed with given push operation |
| 96 | + # It's loose and imperfect assumption that no more than 30 commits will be pushed at once |
| 97 | + fetch-depth: 30 |
| 98 | + # Tag needs to be pushed with real user token |
| 99 | + # (hence we're not relying on actions secrets.GITHUB_TOKEN) |
| 100 | + # Otherwise pushed tag won't trigger the actions workflow |
| 101 | + token: ${{ secrets.USER_GITHUB_TOKEN }} |
| 102 | + |
| 103 | + - name: Resolve last validated commit hash (for `git diff` purposes) |
| 104 | + uses: actions/download-artifact@v2 |
| 105 | + continue-on-error: true |
| 106 | + with: |
| 107 | + name: last-validated-commit-hash |
| 108 | + path: /home/runner |
| 109 | + |
| 110 | + - name: Tag if new version |
| 111 | + run: | |
| 112 | + LAST_VALIDATED_COMMIT_HASH=`cat /home/runner/last-validated-commit-hash` || : |
| 113 | + if [ -n "$LAST_VALIDATED_COMMIT_HASH" ]; |
| 114 | + then |
| 115 | + NEW_VERSION=`git diff -U0 $LAST_VALIDATED_COMMIT_HASH serverless.component.yml | grep 'version: ' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || : |
| 116 | + if [ -n "$NEW_VERSION" ]; |
| 117 | + then |
| 118 | + git tag v$NEW_VERSION |
| 119 | + git push --tags |
| 120 | + fi |
| 121 | + fi |
0 commit comments