|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + tags: |
| 10 | + - v* |
| 11 | + |
| 12 | + # Allows to run this via the Actions tab |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +env: |
| 16 | + REGISTRY: quay.io |
| 17 | + |
| 18 | +jobs: |
| 19 | + lint: |
| 20 | + permissions: |
| 21 | + # Required: allow read access to the content for analysis. |
| 22 | + contents: read |
| 23 | + # Optional: allow read access to pull request. Use with `only-new-issues` option. |
| 24 | + pull-requests: read |
| 25 | + # Optional: Allow write access to checks to allow the action to annotate code in the PR. |
| 26 | + checks: write |
| 27 | + name: Linter |
| 28 | + runs-on: ubuntu-latest |
| 29 | + timeout-minutes: 10 |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v5 |
| 32 | + - uses: actions/setup-go@v5 |
| 33 | + with: |
| 34 | + go-version: "1.25.x" |
| 35 | + cache: false |
| 36 | + - name: golangci-lint |
| 37 | + uses: golangci/golangci-lint-action@v8 |
| 38 | + with: |
| 39 | + # Require: The version of golangci-lint to use. |
| 40 | + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. |
| 41 | + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. |
| 42 | + version: v2.5.0 |
| 43 | + |
| 44 | + check-license: |
| 45 | + name: License scan |
| 46 | + runs-on: ubuntu-latest |
| 47 | + timeout-minutes: 5 |
| 48 | + env: |
| 49 | + REPORT_FILE: gl-license-scanning-report.json |
| 50 | + |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + - uses: actions/setup-go@v5 |
| 54 | + with: |
| 55 | + go-version: "1.25.x" |
| 56 | + - name: License scanning |
| 57 | + run: | |
| 58 | + go install github.com/google/go-licenses@latest |
| 59 | + go-licenses check . --disallowed_types=forbidden,restricted |
| 60 | + - name: Generate license report |
| 61 | + run: | |
| 62 | + go-licenses report . > licenses.csv |
| 63 | + - name: Save license scan report |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: license_scanning |
| 67 | + path: licenses.csv |
| 68 | + |
| 69 | + check-go-releaser: |
| 70 | + name: Go releaser check |
| 71 | + runs-on: ubuntu-latest |
| 72 | + timeout-minutes: 5 |
| 73 | + |
| 74 | + steps: |
| 75 | + - uses: actions/checkout@v4 |
| 76 | + - uses: actions/setup-go@v5 |
| 77 | + with: |
| 78 | + go-version: "1.25.x" |
| 79 | + - name: Run GoReleaser |
| 80 | + uses: goreleaser/goreleaser-action@v5 |
| 81 | + with: |
| 82 | + # either 'goreleaser' (default) or 'goreleaser-pro' |
| 83 | + distribution: goreleaser |
| 84 | + # 'latest', 'nightly', or a semver |
| 85 | + version: v1.25.1 |
| 86 | + args: check |
| 87 | + |
| 88 | + test: |
| 89 | + name: Tests |
| 90 | + needs: |
| 91 | + - lint |
| 92 | + runs-on: ubuntu-latest |
| 93 | + timeout-minutes: 10 |
| 94 | + |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@v4 |
| 97 | + - uses: actions/setup-go@v5 |
| 98 | + with: |
| 99 | + go-version: "1.25.x" |
| 100 | + - name: Run tests |
| 101 | + run: go test -v ./... |
| 102 | + |
| 103 | + publish: |
| 104 | + name: Publish the release |
| 105 | + if: ${{ github.ref_type == 'tag' }} |
| 106 | + needs: |
| 107 | + - test |
| 108 | + runs-on: ubuntu-latest |
| 109 | + timeout-minutes: 15 |
| 110 | + env: |
| 111 | + TAG: ${{ github.ref_name }} |
| 112 | + S3_BUCKET: "s3://cli-dl.stackstate.com/stackstate-backup-cli/" |
| 113 | + QUAY_USER: ${{ secrets.QUAY_USER }} |
| 114 | + QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }} |
| 115 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 116 | + steps: |
| 117 | + - uses: actions/checkout@v4 |
| 118 | + - uses: actions/setup-go@v5 |
| 119 | + with: |
| 120 | + go-version: "1.25.x" |
| 121 | + - name: Log in to the Container registry |
| 122 | + uses: docker/login-action@v3 |
| 123 | + if: github.event_name != 'pull_request' |
| 124 | + with: |
| 125 | + registry: quay.io |
| 126 | + username: ${{ secrets.QUAY_USER }} |
| 127 | + password: ${{ secrets.QUAY_PASSWORD }} |
| 128 | + - name: Log in to the Container registry |
| 129 | + uses: docker/login-action@v3 |
| 130 | + if: github.event_name != 'pull_request' |
| 131 | + with: |
| 132 | + registry: docker.io |
| 133 | + username: ${{ secrets.DOCKER_USER }} |
| 134 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 135 | + - name: Go releaser publish |
| 136 | + uses: goreleaser/goreleaser-action@v5 |
| 137 | + env: |
| 138 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 139 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 140 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 141 | + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} |
| 142 | + with: |
| 143 | + # either 'goreleaser' (default) or 'goreleaser-pro' |
| 144 | + distribution: goreleaser |
| 145 | + # 'latest', 'nightly', or a semver |
| 146 | + version: v1.25.1 |
| 147 | + args: release |
| 148 | + - name: Write latest version to file |
| 149 | + run: mkdir -p dist && echo "${{ env.TAG }}" > dist/LATEST_VERSION |
| 150 | + |
| 151 | + - name: Authenticate with AWS |
| 152 | + uses: aws-actions/configure-aws-credentials@v4 |
| 153 | + with: |
| 154 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 155 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 156 | + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} |
| 157 | + |
| 158 | + - name: Publish latest version to S3 |
| 159 | + run: | |
| 160 | + echo "aws s3 cp dist/LATEST_VERSION ${{ env.S3_BUCKET }}" |
| 161 | + aws s3 cp dist/LATEST_VERSION ${{ env.S3_BUCKET }} |
| 162 | +
|
| 163 | + - name: Publish installers to S3 |
| 164 | + run: | |
| 165 | + echo "aws s3 cp scripts/publish/installers/ ${{ env.S3_BUCKET }} --recursive" |
| 166 | + aws s3 cp scripts/publish/installers/ ${{ env.S3_BUCKET }} --recursive |
0 commit comments