From 4bf8ca67bac15937430ac3b62bc98cf68af96043 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Tue, 4 Jul 2023 09:27:28 +0200 Subject: [PATCH] Align Github actions. (#53) --- .github/workflows/docker.yaml | 55 ++++++++++++++++++++++++++ .github/workflows/latest.yaml | 39 ------------------ .github/workflows/pull_request.yaml | 45 --------------------- .github/workflows/release-drafter.yaml | 15 +++++++ .github/workflows/release.yaml | 35 ---------------- 5 files changed, 70 insertions(+), 119 deletions(-) create mode 100644 .github/workflows/docker.yaml delete mode 100644 .github/workflows/latest.yaml delete mode 100644 .github/workflows/pull_request.yaml create mode 100644 .github/workflows/release-drafter.yaml delete mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..5e915ce --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,55 @@ +--- +name: Docker Build Action +on: + pull_request: + branches: + - master + release: + types: + - published + push: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: Docker Build + runs-on: ubuntu-latest + + steps: + - name: Log in to the container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKER_REGISTRY_USER }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} + + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Go 1.20 + uses: actions/setup-go@v4 + with: + go-version: '1.20.x' + + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + args: --build-tags integration -p bugs -p unused --timeout=5m + + - name: Make tag + run: | + [ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true + [ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true + [ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true + + - name: Build and push image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.tag }} diff --git a/.github/workflows/latest.yaml b/.github/workflows/latest.yaml deleted file mode 100644 index e0d9cdc..0000000 --- a/.github/workflows/latest.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Build latest image - -on: - push: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ${{ secrets.DOCKER_REGISTRY }} - username: ${{ secrets.DOCKER_REGISTRY_USER }} - password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - - - name: Set up Go 1.20 - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - args: -p bugs -p unused --timeout=5m - - - name: Build and push Docker image - run: | - docker build -t ghcr.io/metal-stack/duros-controller . - docker push ghcr.io/metal-stack/duros-controller - - - uses: release-drafter/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml deleted file mode 100644 index 3dd394d..0000000 --- a/.github/workflows/pull_request.yaml +++ /dev/null @@ -1,45 +0,0 @@ -name: Build image from pull request - -on: - pull_request: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Figure out if running fork PR - id: fork - run: '["${{ secrets.DOCKER_REGISTRY_TOKEN }}" == ""] && echo "::set-output name=is_fork_pr::true" || echo "::set-output name=is_fork_pr::false"' - - - name: Set up Go 1.20 - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ${{ secrets.DOCKER_REGISTRY }} - username: ${{ secrets.DOCKER_REGISTRY_USER }} - password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - if: steps.fork.outputs.is_fork_pr == 'false' - - - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - args: -p bugs -p unused --timeout=5m - - - name: Build Docker image - run: | - docker build -t ghcr.io/metal-stack/duros-controller:pr-${GITHUB_HEAD_REF##*/} . - - - name: Push Docker image - run: | - # pull request images are prefixed with 'pr' to prevent them from overriding released images - docker push ghcr.io/metal-stack/duros-controller:pr-${GITHUB_HEAD_REF##*/} - if: steps.fork.outputs.is_fork_pr == 'false' diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml new file mode 100644 index 0000000..da232f3 --- /dev/null +++ b/.github/workflows/release-drafter.yaml @@ -0,0 +1,15 @@ +--- +name: Release Drafter Action + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 39a9b6e..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,35 +0,0 @@ -name: Build image from release tag - -on: - release: - types: - - published - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ${{ secrets.DOCKER_REGISTRY }} - username: ${{ secrets.DOCKER_REGISTRY_USER }} - password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - - - name: Set up Go 1.20 - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - args: -p bugs -p unused --timeout=5m - - - name: Build and push Docker image - run: | - docker build -t ghcr.io/metal-stack/duros-controller:${GITHUB_REF##*/} . - docker push ghcr.io/metal-stack/duros-controller:${GITHUB_REF##*/}