|
| 1 | +name: ci |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + - development |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + id-token: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + name: Build |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Set up nodejs |
| 31 | + uses: actions/setup-node@v3 |
| 32 | + with: |
| 33 | + node-version: 'lts/*' |
| 34 | + cache: 'npm' |
| 35 | + |
| 36 | + - name: npm ci |
| 37 | + run: npm ci |
| 38 | + |
| 39 | + - name: npm check |
| 40 | + run: npm run check |
| 41 | + |
| 42 | + - name: npm test |
| 43 | + run: npm run test -- --coverage |
| 44 | + |
| 45 | + - name: npm build |
| 46 | + run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build |
| 47 | + |
| 48 | + - name: Set VERSION env |
| 49 | + run: echo "VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV |
| 50 | + |
| 51 | + - name: SonarQube Scan (Push) |
| 52 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development') |
| 53 | + uses: SonarSource/[email protected] |
| 54 | + env: |
| 55 | + SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} |
| 56 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + with: |
| 58 | + projectBaseDir: . |
| 59 | + args: > |
| 60 | + -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} |
| 61 | + -Dsonar.projectVersion=${{ env.VERSION }} |
| 62 | + -Dsonar.branch.name=${{ github.ref_name }} |
| 63 | +
|
| 64 | + - name: SonarQube Scan (Pull Request) |
| 65 | + if: github.event_name == 'pull_request' |
| 66 | + uses: SonarSource/[email protected] |
| 67 | + env: |
| 68 | + SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} |
| 69 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + with: |
| 71 | + projectBaseDir: . |
| 72 | + args: > |
| 73 | + -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} |
| 74 | + -Dsonar.projectVersion=${{ env.VERSION }} |
| 75 | + -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} |
| 76 | + -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} |
| 77 | + -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} |
| 78 | +
|
| 79 | + - name: Store assets |
| 80 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development') |
| 81 | + uses: actions/upload-artifact@v3 |
| 82 | + with: |
| 83 | + name: assets |
| 84 | + path: umd/ |
| 85 | + retention-days: 1 |
| 86 | + |
| 87 | + upload-stage: |
| 88 | + name: Upload assets |
| 89 | + runs-on: ubuntu-latest |
| 90 | + needs: build |
| 91 | + if: github.event_name == 'push' && github.ref == 'refs/heads/development' |
| 92 | + strategy: |
| 93 | + matrix: |
| 94 | + environment: |
| 95 | + - stage |
| 96 | + include: |
| 97 | + - environment: stage |
| 98 | + account_id: "079419646996" |
| 99 | + bucket: split-public-stage |
| 100 | + |
| 101 | + steps: |
| 102 | + - name: Download assets |
| 103 | + uses: actions/download-artifact@v3 |
| 104 | + with: |
| 105 | + name: assets |
| 106 | + path: umd |
| 107 | + |
| 108 | + - name: Display structure of assets |
| 109 | + run: ls -R |
| 110 | + working-directory: umd |
| 111 | + |
| 112 | + - name: Configure AWS credentials |
| 113 | + uses: aws-actions/configure-aws-credentials@v1-node16 |
| 114 | + with: |
| 115 | + role-to-assume: arn:aws:iam::${{ matrix.account_id }}:role/gha-public-assets-role |
| 116 | + aws-region: us-east-1 |
| 117 | + |
| 118 | + - name: Upload to S3 |
| 119 | + run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS |
| 120 | + env: |
| 121 | + BUCKET: ${{ matrix.bucket }} |
| 122 | + SOURCE_DIR: ./umd |
| 123 | + DEST_DIR: sdk |
| 124 | + ARGS: --acl public-read --follow-symlinks --cache-control max-age=31536000,public |
| 125 | + |
| 126 | + upload-prod: |
| 127 | + name: Upload assets |
| 128 | + runs-on: ubuntu-latest |
| 129 | + needs: build |
| 130 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 131 | + strategy: |
| 132 | + matrix: |
| 133 | + environment: |
| 134 | + - prod |
| 135 | + include: |
| 136 | + - environment: prod |
| 137 | + account_id: "825951051969" |
| 138 | + bucket: split-public |
| 139 | + |
| 140 | + steps: |
| 141 | + - name: Download assets |
| 142 | + uses: actions/download-artifact@v3 |
| 143 | + with: |
| 144 | + name: assets |
| 145 | + path: umd |
| 146 | + |
| 147 | + - name: Display structure of assets |
| 148 | + run: ls -R |
| 149 | + working-directory: umd |
| 150 | + |
| 151 | + - name: Configure AWS credentials |
| 152 | + uses: aws-actions/configure-aws-credentials@v1-node16 |
| 153 | + with: |
| 154 | + role-to-assume: arn:aws:iam::${{ matrix.account_id }}:role/gha-public-assets-role |
| 155 | + aws-region: us-east-1 |
| 156 | + |
| 157 | + - name: Upload to S3 |
| 158 | + run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS |
| 159 | + env: |
| 160 | + BUCKET: ${{ matrix.bucket }} |
| 161 | + SOURCE_DIR: ./umd |
| 162 | + DEST_DIR: sdk |
| 163 | + ARGS: --acl public-read --follow-symlinks --cache-control max-age=31536000,public |
0 commit comments