diff --git a/.gitea/actions/cd-action.yaml b/.gitea/actions/cd-action.yaml new file mode 100644 index 0000000..c55f6d9 --- /dev/null +++ b/.gitea/actions/cd-action.yaml @@ -0,0 +1,48 @@ +name: CD Action + +on: + workflow_call: + secrets: [REGISTRY_USER, REGISTRY_PASSWORD] + inputs: + DOCKER_REGISTRY: + required: true + type: string + +jobs: + build_and_push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Registry + uses: docker/login-action@v2 + with: + registry: ${{ input.DOCKER_REGISTRY }} + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Get Metadata + id: meta + run: | + echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT + echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + platforms: | + linux/amd64 + linux/arm64 + push: true + tags: | + ${{ input.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }} + ${{ input.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:latest diff --git a/.gitea/actions/ci-action.yaml b/.gitea/actions/ci-action.yaml new file mode 100644 index 0000000..ca4fa06 --- /dev/null +++ b/.gitea/actions/ci-action.yaml @@ -0,0 +1,38 @@ +name: CI Action + +on: + workflow_call: + +jobs: + test: + name: test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + - name: Create cache key + uses: https://gitea.com/actions/go-hashfiles@v0.0.1 + id: hash-go + with: + patterns: | + go.mod + go.sum + - name: cache go + id: cache-go + uses: actions/cache@v4 + with: + path: | + /go_path + /go_cache + key: go_path-${{ steps.hash-go.outputs.hash }} + restore-keys: |- + go_cache-${{ steps.hash-go.outputs.hash }} + - name: build + run: make build + - name: test + run: make test diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index 5407dda..c5947b4 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -1,52 +1,20 @@ name: CD on: - workflow_run: - workflows: - - CI + push: branches: - main - types: - - completed env: DOCKER_REGISTRY: gitea.t000-n.de jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Registry - uses: docker/login-action@v2 - with: - registry: ${{ env.DOCKER_REGISTRY }} - username: ${{ secrets.REGISTRY_USER }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - - name: Get Metadata - id: meta - run: | - echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT - echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT - - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile - platforms: | - linux/amd64 - linux/arm64 - push: true - tags: | - ${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }} - ${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:latest + test: + uses: ./.gitea/actions/ci-action.yaml + + build_and_push: + uses: ./.gitea/actions/cd-action.yaml + with: + DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} + requires: + - test diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 8d5c7d9..cf271da 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -1,9 +1,6 @@ name: CI on: pull_request: - push: - branches: - - main env: GOPATH: /go_path @@ -11,35 +8,5 @@ env: RUNNER_TOOL_CACHE: /toolcache jobs: - testing: - name: test - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - check-latest: true - - name: Create cache key - uses: https://gitea.com/actions/go-hashfiles@v0.0.1 - id: hash-go - with: - patterns: | - go.mod - go.sum - - name: cache go - id: cache-go - uses: actions/cache@v4 - with: - path: | - /go_path - /go_cache - key: go_path-${{ steps.hash-go.outputs.hash }} - restore-keys: |- - go_cache-${{ steps.hash-go.outputs.hash }} - - name: build - run: make build - - name: test - run: make test + test: + uses: ./.gitea/actions/ci-action.yaml