|
| 1 | +name: Continuous Integration |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - exp |
| 8 | + - main |
| 9 | + - feature/** |
| 10 | + tags: ["**"] |
| 11 | + |
| 12 | +permissions: |
| 13 | + id-token: write |
| 14 | + contents: read |
| 15 | + packages: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + test: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Setup go |
| 24 | + uses: actions/setup-go@v5 |
| 25 | + with: |
| 26 | + go-version-file: go.mod |
| 27 | + cache-dependency-path: go.sum |
| 28 | + |
| 29 | + - name: Run test |
| 30 | + run: make _test |
| 31 | + |
| 32 | + lint: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Setup go |
| 38 | + uses: actions/setup-go@v5 |
| 39 | + with: |
| 40 | + go-version-file: go.mod |
| 41 | + cache-dependency-path: go.sum |
| 42 | + |
| 43 | + - name: Run lint |
| 44 | + uses: golangci/golangci-lint-action@v6 |
| 45 | + with: |
| 46 | + version: v1.61 |
| 47 | + args: --timeout=5m |
| 48 | + |
| 49 | + build: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Setup go |
| 55 | + uses: actions/setup-go@v5 |
| 56 | + with: |
| 57 | + go-version-file: go.mod |
| 58 | + cache-dependency-path: go.sum |
| 59 | + |
| 60 | + - name: Build |
| 61 | + env: |
| 62 | + GOOS: linux |
| 63 | + GOARCH: arm64 |
| 64 | + run: make _build |
| 65 | + |
| 66 | + build-and-push-image: |
| 67 | + if: github.ref == 'refs/heads/exp' || startsWith(github.ref, 'refs/heads/feature/') || startsWith(github.ref, 'refs/tags/') |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: |
| 70 | + - test |
| 71 | + - lint |
| 72 | + - build |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Get 10 length commit sha |
| 77 | + if: github.ref == 'refs/heads/exp' || startsWith(github.ref, 'refs/heads/feature/') |
| 78 | + id: short-sha |
| 79 | + run: | |
| 80 | + echo value=$(echo ${{ github.sha }} | cut -c1-10) >> $GITHUB_OUTPUT |
| 81 | +
|
| 82 | + - name: Log in to the Container registry |
| 83 | + uses: docker/login-action@v3 |
| 84 | + with: |
| 85 | + registry: ghcr.io |
| 86 | + username: ${{ github.actor }} |
| 87 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + |
| 89 | + - name: Docker meta |
| 90 | + id: meta |
| 91 | + uses: docker/metadata-action@v5 |
| 92 | + with: |
| 93 | + images: | |
| 94 | + ghcr.io/${{ github.repository }} |
| 95 | + tags: | |
| 96 | + type=raw,priority=100,prefix=exp-,value=${{ steps.short-sha.outputs.value }},enable=${{ startsWith(github.ref, 'refs/heads/exp') }} |
| 97 | + type=raw,priority=100,prefix=feature-,value=${{ steps.short-sha.outputs.value }},enable=${{ startsWith(github.ref, 'refs/heads/feature/') }} |
| 98 | + type=ref,priority=600,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/') }} |
| 99 | +
|
| 100 | + - name: Get current time |
| 101 | + id: time |
| 102 | + shell: sh |
| 103 | + run: | |
| 104 | + echo current_time=$(TZ=Asia/Seoul date +'%Y-%m-%dT%H:%M:%S%z') >> $GITHUB_OUTPUT |
| 105 | +
|
| 106 | + - name: Set up Docker Buildx |
| 107 | + uses: docker/setup-buildx-action@v3 |
| 108 | + with: |
| 109 | + platforms: linux/arm64 |
| 110 | + |
| 111 | + - name: Build image and push to GitHub Container Registry |
| 112 | + uses: docker/build-push-action@v6 |
| 113 | + with: |
| 114 | + context: . |
| 115 | + push: true |
| 116 | + tags: ${{ steps.meta.outputs.tags }} |
| 117 | + platforms: linux/arm64 |
| 118 | + build-args: | |
| 119 | + BUILD_VERSION=${{ github.ref_name }} |
| 120 | + BUILD_COMMIT=${{ github.sha }} |
| 121 | + BUILD_TIME=${{ steps.time.outputs.current_time }} |
0 commit comments