From 42b391fe9b2e37fda60d324f23eeeb8f44c4c9b2 Mon Sep 17 00:00:00 2001 From: Gabriel Prando Date: Wed, 24 Jul 2024 18:31:20 -0300 Subject: [PATCH] Feat: Add GitHub Actions Workflow for CI/CD (#21) Add GitHub Actions Workflow for CI/CD (#21) --- .github/actions/setup-go-and-deps/action.yml | 22 +++++++++++++ .github/workflows/build.yml | 21 ++++++++++++ .github/workflows/dependencies.yml | 14 ++++++++ .github/workflows/deployment.yml | 17 ++++++++++ .github/workflows/lint.yml | 18 +++++++++++ .github/workflows/main.yml | 34 ++++++++++++++++++++ .github/workflows/pre.yml | 14 ++++++++ .github/workflows/test.yml | 15 +++++++++ .gitignore | 2 ++ .tool-versions | 2 ++ 10 files changed, 159 insertions(+) create mode 100644 .github/actions/setup-go-and-deps/action.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/dependencies.yml create mode 100644 .github/workflows/deployment.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pre.yml create mode 100644 .github/workflows/test.yml create mode 100644 .tool-versions diff --git a/.github/actions/setup-go-and-deps/action.yml b/.github/actions/setup-go-and-deps/action.yml new file mode 100644 index 0000000..8b2c956 --- /dev/null +++ b/.github/actions/setup-go-and-deps/action.yml @@ -0,0 +1,22 @@ +name: Setup Go and Dependencies +description: 'Setup Go and Dependencies' + +inputs: + go-version-file: + description: 'The path to the go.mod file' + required: false + default: 'go.mod' + +runs: + using: "composite" + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: ${{ inputs.go-version-file }} + + - name: Install Dependencies + shell: bash + run: go mod tidy \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c457d49 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,21 @@ +on: [workflow_call] +defaults: + run: + shell: bash + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Go and dependencies + uses: ./.github/actions/setup-go-and-deps + - name: build + run: CGO_ENABLED=0 go build -o main . + + - name: upload builded artifact + uses: actions/upload-artifact@v4 + with: + name: main-${{github.sha}} + path: main diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml new file mode 100644 index 0000000..7ce9eff --- /dev/null +++ b/.github/workflows/dependencies.yml @@ -0,0 +1,14 @@ +on: [workflow_call] +defaults: + run: + shell: bash + +jobs: + deps: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Go and dependencies + uses: ./.github/actions/setup-go-and-deps \ No newline at end of file diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml new file mode 100644 index 0000000..e14993a --- /dev/null +++ b/.github/workflows/deployment.yml @@ -0,0 +1,17 @@ +on: [workflow_call] +defaults: + run: + shell: bash + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: download builded artifact + uses: actions/download-artifact@v4 + with: + name: main-${{github.sha}} + + - name: Deploy + run: | + echo "Dummy Deploy..." \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..2e06350 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,18 @@ +on: [workflow_call] +defaults: + run: + shell: bash + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: golang ci lint + uses: golangci/golangci-lint-action@v6 + continue-on-error: true + with: + version: latest + args: --timeout 10m + + \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5b3f449 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,34 @@ +run-name: main workflow +on: + push: + branches: + - main + - master + - develop + pull_request: + branches: + - main + - master + - develop +defaults: + run: + shell: bash + +jobs: + pre: + uses: ./.github/workflows/pre.yml + deps: + needs: pre + uses: ./.github/workflows/dependencies.yml + lint: + needs: deps + uses: ./.github/workflows/lint.yml + test: + needs: deps + uses: ./.github/workflows/test.yml + build: + needs: [test, lint] + uses: ./.github/workflows/build.yml + deploy: + needs: build + uses: ./.github/workflows/deployment.yml \ No newline at end of file diff --git a/.github/workflows/pre.yml b/.github/workflows/pre.yml new file mode 100644 index 0000000..8c71bbe --- /dev/null +++ b/.github/workflows/pre.yml @@ -0,0 +1,14 @@ +on: [workflow_call] + +defaults: + run: + shell: bash + +jobs: + pre: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: pre script + run: | + echo "Running pre script" \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5b4f5f2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +on: [workflow_call] +defaults: + run: + shell: bash + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Go and dependencies + uses: ./.github/actions/setup-go-and-deps + - name: test + run: go test -v ./... \ No newline at end of file diff --git a/.gitignore b/.gitignore index 13f670b..9c64281 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ go-base # Output of the go coverage tool, specifically when used with LiteIDE *.out + +main \ No newline at end of file diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..4efb38a --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +golang 1.18 +golangci-lint 1.59.1 \ No newline at end of file