From cff8325003fe0664bb65d19287da0b01fa965573 Mon Sep 17 00:00:00 2001 From: Hoang Trinh Date: Thu, 18 Jan 2024 22:57:23 +0700 Subject: [PATCH] ci: add release ci --- .github/pull_request_template.md | 18 +++++++++ .github/workflows/ci.yml | 50 ++++++++++++++++++++++++ .github/workflows/release.yml | 67 ++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..f082d63 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,18 @@ + + + +## Why did we need it? + + +## Related Issue + + + + + +## How Has This Been Tested? + + + + +## Screenshots (if appropriate): \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c09c93a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: Go Project CI + +concurrency: + group: ci-workflow-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + +on: + workflow_dispatch: + push: + branches: + - main + - release-v** + pull_request: + +env: + SERVICE: logger + +jobs: + lint: + name: Run golangci-lint + runs-on: [ ubuntu-22.04 ] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: "1.19.x" + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.52.2 + skip-pkg-cache: true + skip-build-cache: true + args: --timeout=2m + test: + runs-on: [ ubuntu-22.04 ] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: "1.19.x" + - name: Run tests + run: go test -race -coverprofile cover.out -vet=off ./... + + - name: Print coverage + run: | + go tool cover -func cover.out | grep total | awk '{notice="Statement Coverage: " substr($3, 1, length($3))} END {print notice}' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c7df8d2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,67 @@ +name: 'Release' + +permissions: write-all + +on: + workflow_dispatch: + inputs: + version: + description: 'Release version' + type: string + required: true + +jobs: + prepare: + runs-on: [ ubuntu-22.04 ] + outputs: + version_tag: ${{ steps.version_tag.outputs.value }} + build_date: ${{ steps.build_date.outputs.value }} + steps: + - name: Format version tag + shell: bash + id: version_tag + env: + INPUT_TAG: ${{ github.event.inputs.version }} + run: | + TAG=${INPUT_TAG#v} + echo "::set-output name=value::v$TAG" + - name: Build date + shell: bash + id: build_date + run: echo "::set-output name=value::$(date +%FT%T%z)" + + release: + needs: + - prepare + runs-on: [ ubuntu-22.04 ] + env: + VERSION_TAG: ${{ needs.prepare.outputs.version_tag }} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: "1.19.x" + + - name: Setup Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Create tag + run: | + git tag -d "$VERSION_TAG" 2> /dev/null || echo "Release tag '$VERSION_TAG' does NOT exist" + git tag --annotate --message "dmm-aggregator-backend $VERSION_TAG" "$VERSION_TAG" + git push origin "refs/tags/$VERSION_TAG" + + - name: Create release + uses: softprops/action-gh-release@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag_name: ${{ env.VERSION_TAG }} + prerelease: false + name: "Logger ${{ env.VERSION_TAG }}"