|
| 1 | + |
| 2 | +name: CI Actions |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - master |
| 10 | +jobs: |
| 11 | + workflow: |
| 12 | + name: Lint/Build/Test |
| 13 | + |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + go-version: [1.18.x] |
| 17 | + os: [ ubuntu-latest ] |
| 18 | + runs-on: ${{ matrix.os }} |
| 19 | + |
| 20 | + steps: |
| 21 | + |
| 22 | + - name: Configure git for private modules |
| 23 | + env: |
| 24 | + TOKEN: ${{ secrets.RESTRICTED_REPO_TOKEN}} |
| 25 | + run: git config --global url."https://${TOKEN}:[email protected]/".insteadOf "https://github.com/" |
| 26 | + |
| 27 | + - name: Install Go |
| 28 | + uses: actions/setup-go@v2 |
| 29 | + with: |
| 30 | + go-version: ${{matrix.go-version}} |
| 31 | + |
| 32 | + - name: Checkout Code Base |
| 33 | + uses: actions/checkout@v3 |
| 34 | + with: |
| 35 | + fetch-depth: '0' |
| 36 | + |
| 37 | + - name: Restore Go Module Cache |
| 38 | + uses: actions/cache@v2 |
| 39 | + with: |
| 40 | + path: ~/go/internal/mod |
| 41 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 42 | + restore-keys: | |
| 43 | + ${{ runner.os }}-go- |
| 44 | +
|
| 45 | + - name: Make Lint |
| 46 | + run: | |
| 47 | + export GOPATH=$HOME/go |
| 48 | + export PATH=$PATH:$GOPATH/bin |
| 49 | + export GOPRIVATE=github.com/AfterShip/* |
| 50 | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3 |
| 51 | + go mod tidy |
| 52 | + make lint |
| 53 | +
|
| 54 | + - name: Test |
| 55 | + run: make test |
| 56 | + |
| 57 | + - name: SonarQube Scan On PR |
| 58 | + if: ${{ github.event_name == 'pull_request' }} |
| 59 | + uses: sonarsource/sonarqube-scan-action@master |
| 60 | + with: |
| 61 | + projectBaseDir: . |
| 62 | + args: > |
| 63 | + -Dsonar.go.coverage.reportPaths=coverage.out |
| 64 | + -Dsonar.exclusions=**/*_test.go,**/*.gen.go,**/*.py |
| 65 | + -Dsonar.projectKey=${{ github.event.repository.name }} |
| 66 | + -Dsonar.pullrequest.provider=github |
| 67 | + -Dsonar.pullrequest.github.repository=${{ github.repository }} |
| 68 | + -Dsonar.pullrequest.key=${{ github.event.number }} |
| 69 | + -Dsonar.pullrequest.branch=PR |
| 70 | + -Dsonar.pullrequest.base=${{ github.base_ref }} |
| 71 | + -Dsonar.qualitygate.wait=true |
| 72 | + env: |
| 73 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 74 | + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} |
| 75 | + |
| 76 | + - name: Get branch name (merge) |
| 77 | + if: ${{ github.event_name != 'pull_request' }} |
| 78 | + shell: bash |
| 79 | + run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV |
| 80 | + |
| 81 | + - name: SonarQube Scan On Push |
| 82 | + if: ${{ github.event_name != 'pull_request' }} |
| 83 | + uses: sonarsource/sonarqube-scan-action@master |
| 84 | + with: |
| 85 | + projectBaseDir: . |
| 86 | + args: > |
| 87 | + -Dsonar.go.coverage.reportPaths=coverage.out |
| 88 | + -Dsonar.exclusions=**/*_test.go,**/*.gen.go,**/*.py |
| 89 | + -Dsonar.projectKey=${{ github.event.repository.name }} |
| 90 | + -Dsonar.pullrequest.provider=github |
| 91 | + -Dsonar.pullrequest.github.repository=${{ github.repository }} |
| 92 | + -Dsonar.branch.name=${{ env.BRANCH_NAME }} |
| 93 | + -Dsonar.qualitygate.wait=true |
| 94 | + env: |
| 95 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 96 | + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} |
0 commit comments