|
| 1 | +name: CI/CD - v0.3 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + |
| 7 | +jobs: |
| 8 | + Test: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Go |
| 16 | + uses: actions/setup-go@v4 |
| 17 | + with: |
| 18 | + go-version: "1.22" |
| 19 | + |
| 20 | + - name: Cache Go modules |
| 21 | + uses: actions/cache@v4 |
| 22 | + with: |
| 23 | + path: | |
| 24 | + ~/.cache/go-build |
| 25 | + ~/go/pkg/mod |
| 26 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 27 | + restore-keys: | |
| 28 | + ${{ runner.os }}-go- |
| 29 | +
|
| 30 | + - name: Install static analysis tools |
| 31 | + run: | |
| 32 | + go install golang.org/x/lint/golint@latest |
| 33 | + go install honnef.co/go/tools/cmd/staticcheck@latest |
| 34 | + go install github.com/securego/gosec/v2/cmd/gosec@latest |
| 35 | + go install github.com/psampaz/go-mod-outdated@latest |
| 36 | + go install github.com/remyoudompheng/go-misc/deadcode@latest |
| 37 | +
|
| 38 | + - name: Go static analysis |
| 39 | + run: | |
| 40 | + golint ./... |
| 41 | + staticcheck ./... |
| 42 | + go vet ./... |
| 43 | + deadcode . |
| 44 | +
|
| 45 | + - name: Dependency management |
| 46 | + run: | |
| 47 | + go mod vendor |
| 48 | + go mod verify |
| 49 | + go mod tidy |
| 50 | +
|
| 51 | + - name: Security scanning |
| 52 | + run: | |
| 53 | + gosec ./... |
| 54 | +
|
| 55 | + Build: |
| 56 | + needs: Test |
| 57 | + runs-on: ubuntu-latest |
| 58 | + |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v4 |
| 61 | + |
| 62 | + - name: Set up Docker Buildx |
| 63 | + uses: docker/setup-buildx-action@v3 |
| 64 | + |
| 65 | + - name: Login to DockerHub |
| 66 | + uses: docker/login-action@v3 |
| 67 | + with: |
| 68 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 69 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 70 | + |
| 71 | + - name: Docker build and push |
| 72 | + run: | |
| 73 | + docker buildx build \ |
| 74 | + --platform linux/amd64 \ |
| 75 | + --pull \ |
| 76 | + --build-arg VERSION=v${{ github.run_number }} \ |
| 77 | + --build-arg GIT_COMMIT=${{ github.sha }} \ |
| 78 | + --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ |
| 79 | + --cache-from supporttools/go-sql-proxy:latest \ |
| 80 | + -t supporttools/go-sql-proxy:"0.3.${{ github.run_number }}" \ |
| 81 | + -t supporttools/go-sql-proxy:latest \ |
| 82 | + --push \ |
| 83 | + -f Dockerfile . |
| 84 | +
|
| 85 | + Publish: |
| 86 | + runs-on: ubuntu-latest |
| 87 | + needs: |
| 88 | + - Build |
| 89 | + |
| 90 | + steps: |
| 91 | + - name: Checkout repository |
| 92 | + uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Set up Helm |
| 95 | + uses: azure/setup-helm@v4.2.0 |
| 96 | + |
| 97 | + - name: Helm Lint |
| 98 | + run: helm lint charts/go-sql-proxy/ |
| 99 | + |
| 100 | + - name: Set up Helm |
| 101 | + uses: azure/setup-helm@v1 |
| 102 | + with: |
| 103 | + version: v3.7.1 |
| 104 | + |
| 105 | + - name: Package Helm chart |
| 106 | + run: | |
| 107 | + export CHART_VERSION="0.3.${{ github.run_number }}" |
| 108 | + export APP_VERSION="0.3.${{ github.run_number }}" |
| 109 | + export IMAGE_TAG="0.3.${{ github.run_number }}" |
| 110 | + echo "CHART_VERSION=${CHART_VERSION}" |
| 111 | + echo "APP_VERSION=${APP_VERSION}" |
| 112 | + envsubst < charts/go-sql-proxy/Chart.yaml.template > charts/go-sql-proxy/Chart.yaml |
| 113 | + envsubst < charts/go-sql-proxy/values.yaml.template > charts/go-sql-proxy/values.yaml |
| 114 | + helm package charts/go-sql-proxy --destination helm/repo |
| 115 | +
|
| 116 | + - name: Checkout helm-chart repository |
| 117 | + uses: actions/checkout@v4 |
| 118 | + with: |
| 119 | + repository: supporttools/helm-chart |
| 120 | + path: helm-chart |
| 121 | + token: ${{ secrets.BOT_TOKEN }} |
| 122 | + |
| 123 | + - name: Configure Git |
| 124 | + run: | |
| 125 | + git config --global user.email "github-action@users.noreply.github.com" |
| 126 | + git config --global user.name "GitHub Action" |
| 127 | +
|
| 128 | + - name: Update Helm repository |
| 129 | + run: | |
| 130 | + cp helm/repo/go-sql-proxy-*.tgz helm-chart/ |
| 131 | + cd helm-chart |
| 132 | + helm repo index . --url https://charts.support.tools/ |
| 133 | + git add . |
| 134 | + git commit -m "Update Helm chart for go-sql-proxy" |
| 135 | + git push |
0 commit comments