From 6f800491dd5c31b75d124718978cfc2c353fa9bc Mon Sep 17 00:00:00 2001 From: David ALEXANDRE Date: Wed, 5 Jul 2023 13:20:05 +0200 Subject: [PATCH] chore: add github action workflow --- .github/workflows/check.yaml | 34 +++++++++++++++ .github/workflows/create_release.yaml | 63 +++++++++++++++++++++++++++ .github/workflows/enforce-labels.yaml | 14 ++++++ .github/workflows/release.yaml | 60 +++++++++++++++++++++++++ .github/workflows/release_tags.yaml | 55 +++++++++++++++++++++++ 5 files changed, 226 insertions(+) create mode 100644 .github/workflows/check.yaml create mode 100644 .github/workflows/create_release.yaml create mode 100644 .github/workflows/enforce-labels.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/release_tags.yaml diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..3d4e466 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,34 @@ +name: Check + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Git Checkout + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19 + + - name: Test + run: go test -v -coverprofile=coverage.txt -covermode=atomic ./... + + - name: Build + run: go build -v ./... + + - name: coverage + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: unittests + fail_ci_if_error: false # optional (default = false) + verbose: false # optional (default = false) + diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml new file mode 100644 index 0000000..1fee69c --- /dev/null +++ b/.github/workflows/create_release.yaml @@ -0,0 +1,63 @@ +on: + pull_request: + types: closed + +jobs: + build: + runs-on: ubuntu-latest + if: github.event.pull_request.merged + steps: + - uses: actions/checkout@v3 + - name: Tag and prepare release + id: tag_and_prepare_release + uses: K-Phoen/semver-release-action@master + with: + release_branch: main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload release notes + if: steps.tag_and_prepare_release.outputs.tag + uses: Roang-zero1/github-create-release-action@v3 + with: + created_tag: ${{ steps.tag_and_prepare_release.outputs.tag }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build variables + id: build_var + run: | + echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/} + echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/} + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + echo ::set-output name=BUILD_DATE::$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo ::set-output name=PROJECT_URL::${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} + echo ::set-output name=VCS_REF::$GITHUB_SHA + + - name: Build and push Docker images + id: docker_build + uses: docker/build-push-action@v4 + with: + push: true + build-args: | + VERSION=${{ steps.tag_and_prepare_release.outputs.tag }} + VCS_REF=${{ steps.build_var.outputs.VCS_REF }} + BUILD_DATE=${{ steps.build_var.outputs.BUILD_DATE }} + PROJECT_URL=${{ steps.build_var.outputs.PROJECT_URL }} + tags: | + w6dio/bblfshd:${{ steps.tag_and_prepare_release.outputs.tag }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/enforce-labels.yaml b/.github/workflows/enforce-labels.yaml new file mode 100644 index 0000000..103a6ab --- /dev/null +++ b/.github/workflows/enforce-labels.yaml @@ -0,0 +1,14 @@ +name: Enforce PR labels + +on: + pull_request: + types: [labeled, unlabeled, opened, edited, synchronize] +jobs: + enforce-label: + runs-on: ubuntu-latest + steps: + - uses: yogevbd/enforce-label-action@2.1.0 + with: + REQUIRED_LABELS_ANY: "major,minor,patch" + REQUIRED_LABELS_ANY_DESCRIPTION: "Select at least one label ['major','minor','patch']" + BANNED_LABELS: "banned" \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..ef2cdf7 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,60 @@ +name: Release latest docker image + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + + - name: Build variables + id: build_var + run: | + echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/} + echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/} + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + echo ::set-output name=BUILD_DATE::$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo ::set-output name=PROJECT_URL::${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} + echo ::set-output name=VCS_REF::$GITHUB_SHA + + - name: Build and push Docker images + id: docker_build + uses: docker/build-push-action@v4 + with: + push: true + build-args: | + VERSION=${{ steps.build_var.outputs.SOURCE_BRANCH }} + VCS_REF=${{ steps.build_var.outputs.VCS_REF }} + BUILD_DATE=${{ steps.build_var.outputs.BUILD_DATE }} + PROJECT_URL=${{ steps.build_var.outputs.PROJECT_URL }} + tags: | + w6dio/bblfshd:latest + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + diff --git a/.github/workflows/release_tags.yaml b/.github/workflows/release_tags.yaml new file mode 100644 index 0000000..c2a7f02 --- /dev/null +++ b/.github/workflows/release_tags.yaml @@ -0,0 +1,55 @@ +name: Release docker image + +on: + push: + tags: + - v* + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build variables + id: build_var + run: | + echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/} + echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/} + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + echo ::set-output name=BUILD_DATE::$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo ::set-output name=PROJECT_URL::${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} + echo ::set-output name=VCS_REF::$GITHUB_SHA + + - name: Build and push Docker images + id: docker_build + uses: docker/build-push-action@v4 + with: + push: true + build-args: | + VERSION=${{ steps.build_var.outputs.SOURCE_TAG }} + VCS_REF=${{ steps.build_var.outputs.VCS_REF }} + BUILD_DATE=${{ steps.build_var.outputs.BUILD_DATE }} + PROJECT_URL=${{ steps.build_var.outputs.PROJECT_URL }} + tags: | + w6dio/bblfshd:${{ steps.build_var.outputs.SOURCE_TAG }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }}