diff --git a/.github/issue-clean-sandbox.md b/.github/issue-clean-sandbox.md new file mode 100644 index 0000000..e010b1d --- /dev/null +++ b/.github/issue-clean-sandbox.md @@ -0,0 +1,17 @@ +# title + +An example issue created using content from [example-content/output.md](https://github.com/peter-evans/create-issue-from-file/blob/main/example-content/output.md) + +## subtitle + +Some text + +- bullet points +- bullet points + +"quoted string" + +```python +s = "syntax highlighting" +print(s) +``` \ No newline at end of file diff --git a/.github/issue-spawn-latest.md b/.github/issue-spawn-latest.md new file mode 100644 index 0000000..e010b1d --- /dev/null +++ b/.github/issue-spawn-latest.md @@ -0,0 +1,17 @@ +# title + +An example issue created using content from [example-content/output.md](https://github.com/peter-evans/create-issue-from-file/blob/main/example-content/output.md) + +## subtitle + +Some text + +- bullet points +- bullet points + +"quoted string" + +```python +s = "syntax highlighting" +print(s) +``` \ No newline at end of file diff --git a/.github/issue-spawn-release.md b/.github/issue-spawn-release.md new file mode 100644 index 0000000..e010b1d --- /dev/null +++ b/.github/issue-spawn-release.md @@ -0,0 +1,17 @@ +# title + +An example issue created using content from [example-content/output.md](https://github.com/peter-evans/create-issue-from-file/blob/main/example-content/output.md) + +## subtitle + +Some text + +- bullet points +- bullet points + +"quoted string" + +```python +s = "syntax highlighting" +print(s) +``` \ No newline at end of file diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..ac6c1c3 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,28 @@ +"[#] ci/cd": + - '.github/*' + - '.github/**/*' + +"[#] deps": + - 'go.mod' + - 'go.sum' + +"[#] doc": + - '*.md' + - 'doc/*' + - 'doc/**/*' + - 'examples/**/*' + +"[#] cloud": + - 'cdk.json' + - 'cloud/*' + - 'cloud/**/*' + +"[#] core": + - '*.go' + +"[#] rest api": + - 'http/*' + - 'http/**/*' + - 'cmd/lambda/*' + - 'cmd/lambda/**/*' + diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..f2fc587 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,154 @@ +## +## Inspired by Same GitHub Labels +## https://medium.com/@dave_lunny/sane-github-labels-c5d2e6004b63 +## +## [T] - Type prefix +## [P] - Priority prefix +## [@] - State prefix +## [A] - Automation prefix +## [#] - package / category prefix +## +## How To Use +## npm install -g github-label-sync +## github-label-sync --access-token xxxxxx --labels .github/labels.yml fogfish/blueprint-serverless-golang +## + +## +## [T] Type labels +- name: "[T] bug" + color: "ee0701" + aliases: [] + description: the bug report + +- name: "[T] epic" + color: "fbca04" + aliases: [] + description: the epic + +- name: "[T] feature" + color: "7057ff" + aliases: [] + description: the feature, enabler epic or other tech activity + +- name: "[T] security" + color: "cc317c" + aliases: [] + description: security issues or concerns within the software + +- name: "[T] resilience" + color: "660033" + aliases: [] + description: resilience concerns within the software + +- name: "[T] user story" + color: "fef2c0" + aliases: [] + description: user story + +- name: "[T] enabler" + color: "7c5d91" + aliases: [] + description: enabler activities + +## +## [P] Priority labels +- name: "[P] critical" + color: "b30408" + aliases: [] + description: critical issue, immediate fix is required + +- name: "[P] high" + color: "f4AA3e" + aliases: [] + description: high priority issue + +- name: "[P] medium" + color: "31689e" + aliases: [] + description: medium priority issue + +- name: "[P] low" + color: "0a9203" + aliases: [] + description: low priority issue + +- name: "[P] release" + color: "ed7655" + aliases: [] + description: required by upcoming release + +## +## [@] State labels +- name: "[@] blocked" + color: "be1910" + aliases: [] + description: progress is blocked by other issue + +- name: "[@] help wanted" + color: "128a0c" + aliases: [] + description: team or community help is wanted on the issue + +- name: "[@] on hold" + color: "f9d0c4" + aliases: [] + description: development is on hold until further notice + +- name: "[@] wontfix" + color: "e2e4e8" + aliases: [] + description: the issue would not be resolved due to the reason + +- name: "[@] review" + color: "006666" + aliases: [] + description: the issue is under the review + +- name: "[@] require feedback" + color: "333399" + aliases: [] + description: the feedback from author is required + +## +## [A] Automation labels +- name: "[A] deploy" + color: "ffccf1" + aliases: [] + description: request GitHub Action to deploy + +## +## [#] Package / Category labels +- name: "[#] ci/cd" + color: "3978e1" + aliases: [] + description: changes to CI/CD configuration + +- name: "[#] deps" + color: "3978e1" + aliases: [] + description: changes to package dependencies + +- name: "[#] doc" + color: "3978e1" + aliases: [] + description: changes to documentation + +- name: "[#] cloud" + color: "3978e1" + aliases: [] + description: changes to cloud infrastructure and its configuration + +- name: "[#] core" + color: "3978e1" + aliases: [] + description: changes to core business logic + +- name: "[#] rest api" + color: "3978e1" + aliases: [] + description: changes to public restful api + + + + + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea85147..4e81be8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,41 +6,31 @@ on: - /refs/heads/main jobs: - it: + + cloud: strategy: matrix: stack: [blueprint-golang] + runs-on: ubuntu-latest steps: - ## - ## setup environment - - name: golang - uses: actions/setup-go@v2 + - uses: actions/checkout@v2 + + - uses: peter-evans/create-issue-from-file@v4 + id: spawn-latest with: - go-version: 1.18 + title: Spawn `${{ matrix.stack }}` latest commit to cloud + content-filepath: ./.github/issue-spawn-latest.md - - name: checkout - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.18 - name: go get tools run: | npm install -g aws-cdk - - name: go build - run: | - go build -v ./... - - - name: go test - run: | - go test -v -coverprofile=profile.cov $(go list ./... | grep -v /examples/) - env: - GOPATH: /home/runner/work/${{ github.event.repository.name }}/go - - - uses: shogo82148/actions-goveralls@v1 - with: - path-to-profile: profile.cov - ## ## deploys application to aws - name: aws access @@ -65,3 +55,9 @@ jobs: run: | echo ::set-output name=target::$(jq -r '.["${{ matrix.stack }}-latest"] | to_entries | .[] | select(.key|test("GatewayEndpoint.*")) | .value ' < $GITHUB_WORKSPACE/stack.json) + - uses: peter-evans/close-issue@v2 + with: + issue-number: ${{ steps.spawn-latest.outputs.issue-number }} + comment: | + Latest version of **${{ matrix.stack }}** is deployed to cloud environment: + - **url**: ${{ steps.discover.outputs.target }} diff --git a/.github/workflows/carry.yml b/.github/workflows/carry.yml index 73f81ae..2035dcb 100644 --- a/.github/workflows/carry.yml +++ b/.github/workflows/carry.yml @@ -8,27 +8,26 @@ jobs: strategy: matrix: stack: [blueprint-golang] + runs-on: ubuntu-latest steps: - ## - ## setup environment - - name: golang - uses: actions/setup-go@v2 + - uses: actions/checkout@v2 + + - uses: peter-evans/create-issue-from-file@v4 + id: spawn-release with: - go-version: 1.18 + title: Spawn `${{ matrix.stack }}` release ${{ github.event.release.name }} to cloud + content-filepath: ./.github/issue-spawn-release.md - - name: checkout - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.18 - ## - ## fetch deps - name: go get tools run: | npm install -g aws-cdk - ## - ## deploys application to aws - name: aws access uses: aws-actions/configure-aws-credentials@v1 with: @@ -51,3 +50,10 @@ jobs: run: | echo ::set-output name=target::$(jq -r '.["${{ matrix.stack }}-${{ github.event.release.name }}"] | to_entries | .[] | select(.key|test("GatewayEndpoint.*")) | .value ' < $GITHUB_WORKSPACE/stack.json) + - uses: peter-evans/close-issue@v2 + with: + issue-number: ${{ steps.spawn-release.outputs.issue-number }} + comment: | + Release ${{ github.event.release.name }} of **${{ matrix.stack }}** is deployed to cloud environment: + - **url**: ${{ steps.discover.outputs.target }} + diff --git a/.github/workflows/clean.yml b/.github/workflows/check-clean.yml similarity index 55% rename from .github/workflows/clean.yml rename to .github/workflows/check-clean.yml index 904f8c8..3114f66 100644 --- a/.github/workflows/clean.yml +++ b/.github/workflows/check-clean.yml @@ -12,18 +12,27 @@ jobs: strategy: matrix: stack: [blueprint-golang] + runs-on: ubuntu-latest steps: - ## - ## setup environment - - name: golang - uses: actions/setup-go@v2 + - uses: actions/checkout@v2 + + - uses: peter-evans/create-issue-from-file@v4 + id: clean-sandbox with: - go-version: 1.18 + title: Destroy sandbox pr${{ github.event.number }} of `${{ matrix.stack }}` + content-filepath: ./.github/issue-clean-sandbox.md - - name: checkout - uses: actions/checkout@v2 + - uses: peter-evans/create-or-update-comment@v2 + with: + issue-number: ${{ github.event.number }} + body: | + destroying #${{ steps.destroy-sandbox.outputs.issue-number }} + + - uses: actions/setup-go@v2 + with: + go-version: 1.18 ## ## fetch deps @@ -47,7 +56,9 @@ jobs: env: GOPATH: /home/runner/work/${{ github.event.repository.name }}/go - - uses: thollander/actions-comment-pull-request@v1 + + - uses: peter-evans/close-issue@v2 with: - message: '**sandbox** #${{ github.event.number }} is destroyed successfully.' - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ steps.clean-sandbox.outputs.issue-number }} + comment: | + Sandbox pr${{ github.event.number }} of **${{ matrix.stack }}** is destroyed. diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml new file mode 100644 index 0000000..edea816 --- /dev/null +++ b/.github/workflows/check-code.yml @@ -0,0 +1,26 @@ +## +## Quality checks +## +name: check +on: + pull_request: + types: + - opened + - synchronize + +jobs: + + code: + runs-on: ubuntu-latest + steps: + + - uses: actions/setup-go@v2 + with: + go-version: 1.18 + + - uses: actions/checkout@v3 + + - uses: dominikh/staticcheck-action@v1.2.0 + with: + version: "2022.1" + install-go: false diff --git a/.github/workflows/spawn.yml b/.github/workflows/check-spawn.yml similarity index 71% rename from .github/workflows/spawn.yml rename to .github/workflows/check-spawn.yml index a24917c..1fa05d4 100644 --- a/.github/workflows/spawn.yml +++ b/.github/workflows/check-spawn.yml @@ -12,28 +12,22 @@ jobs: strategy: matrix: stack: [blueprint-golang] + + if: github.event.label.name == '[A] deploy' + runs-on: ubuntu-latest - if: github.event.label.name == '[@] deploy' steps: - ## - ## setup environment - - name: golang - uses: actions/setup-go@v2 + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 with: go-version: 1.18 - - name: checkout - uses: actions/checkout@v2 - - ## - ## fetches deps - name: go get tools run: | npm install -g aws-cdk - ## - ## deploys application to aws - name: aws access uses: aws-actions/configure-aws-credentials@v1 with: @@ -56,14 +50,16 @@ jobs: run: | echo ::set-output name=target::$(jq -r '.["${{ matrix.stack }}-pr${{ github.event.number }}"] | to_entries | .[] | select(.key|test("GatewayEndpoint.*")) | .value ' < $GITHUB_WORKSPACE/stack.json) - - name: comment - uses: thollander/actions-comment-pull-request@v1 + - uses: peter-evans/create-or-update-comment@v2 with: - message: '**sandbox** #${{ github.event.number }} is spawned: ${{ steps.discover.outputs.target }}' - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.number }} + body: | + Sandbox for **${{ matrix.stack }}** is deployed to cloud environment: + - **url**: ${{ steps.discover.outputs.target }} + reactions: rocket - uses: buildsville/add-remove-label@v1 with: token: ${{secrets.GITHUB_TOKEN}} - label: '[@] deploy' + label: '[A] deploy' type: remove diff --git a/.github/workflows/check-test.yml b/.github/workflows/check-test.yml new file mode 100644 index 0000000..7fefa38 --- /dev/null +++ b/.github/workflows/check-test.yml @@ -0,0 +1,42 @@ +## +## Unit Tests & Coverage +## +name: test +on: + pull_request: + types: + - opened + - synchronize + + push: + branches: + - main + - /refs/heads/main + +jobs: + + unit: + runs-on: ubuntu-latest + steps: + + - uses: actions/setup-go@v2 + with: + go-version: 1.18 + + - uses: actions/checkout@v2 + + - name: go build + run: | + go build ./... + + - name: go test + run: | + go test -v -coverprofile=profile.cov $(go list ./... | grep -v /examples/) + env: + ## GOPATH required to build serverless app inside unittest + GOPATH: /home/runner/work/${{ github.event.repository.name }}/go + + - uses: shogo82148/actions-goveralls@v1 + continue-on-error: true + with: + path-to-profile: profile.cov diff --git a/.github/workflows/check-triage.yml b/.github/workflows/check-triage.yml new file mode 100644 index 0000000..73c35d7 --- /dev/null +++ b/.github/workflows/check-triage.yml @@ -0,0 +1,22 @@ +name: triage +on: + pull_request: + types: + - opened + - synchronize + +jobs: + label: + permissions: + contents: read + pull-requests: write + + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v3 + + - uses: actions/labeler@v4 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + sync-labels: true diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml deleted file mode 100644 index 323ab13..0000000 --- a/.github/workflows/check.yml +++ /dev/null @@ -1,59 +0,0 @@ -## -## checks Golang -## -name: check -on: - pull_request: - types: - - opened - - synchronize - -jobs: - - lint: - runs-on: ubuntu-latest - steps: - - - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - uses: actions/checkout@v3 - - # disable linter due to linters crash - # - uses: golangci/golangci-lint-action@v3.1.0 - # with: - # version: latest - # args: --verbose - - - name: go vet - run: | - go vet ./... - - check: - runs-on: ubuntu-latest - steps: - - ## - ## setup environment - - name: golang - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: checkout - uses: actions/checkout@v2 - - - name: go build - run: | - go build -v ./... - - - name: go test - run: | - go test -v -coverprofile=profile.cov $(go list ./... | grep -v /examples/) - env: - GOPATH: /home/runner/work/${{ github.event.repository.name }}/go - - - uses: shogo82148/actions-goveralls@v1 - with: - path-to-profile: profile.cov diff --git a/README.md b/README.md index c80b7d1..69719a2 100644 --- a/README.md +++ b/README.md @@ -168,15 +168,28 @@ cdk destroy ## Continuos Delivery -Continuos Integration and Delivery is implemented using GitHub Actions. It consists of multiple [.github/workflows](.github/workflows): +Continuos Integration and Delivery is implemented using GitHub Actions. It consists of multiple [.github/workflows](.github/workflows). -* **checks** (`check.yml`) the quality of software assets with scope on unit tests only. Checks are executed in parallel for application logic and infrastructure every time a new change is proposed via Pull Request. -* **spawns** (`spawn.yml`) a sandbox(ed) deployment of the application to target AWS account for continuous integrations; -* **builds** (`build.yml`) validates quality of `main` branch once Pull Request is merge. Upon the quality check completion, the pipeline deploys changes to the development environment at target AWS account; -* **carries** (`carry.yml`) "immutable" application snapshot to production environment when GitHub release is published; +`AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY` are required to enable deployment by GitHub Actions. Store these credentials to secret key vault at your fork settings (Your Fork > Settings > Secrets). + +### Check quality of Pull Request + +The quality checks are executed every time a new change is proposed via Pull Request: +* **checks** (`check-code.yml`) evaluates a quality of source code and reviews proposed changes (pull requests) using static code analysis. +* **tests** (`check-test.yml`) the quality of software assets with scope on unit tests only and measures the test coverage. +* **spawns** (`check-spawn.yml`) a sandbox(ed) deployment of the application to target AWS account for continuous integrations (optionally executed if pull request is marked with `[@] deploy` label); * **cleans** (`clean.yml`) sandbox environment after Pull Request is either merged or closed. -`AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY` are required to enable deployment by GitHub Actions. Store these credentials to secret key vault at your fork settings (Your Fork > Settings > Secrets). +### Check quality of `main` branch + +The quality checks are executed every time a pull request is merged into pipeline: +* **tests** (`check-test.yml`) the quality of software assets with scope on unit tests only and measures the test coverage. +* **builds** (`build.yml`) validates quality of `main` branch once Pull Request is merge by deploying changes to the development environment at target AWS account; + +### Release of `main` branch + +The quality checks are executed every time a new release is created: +* **carries** (`carry.yml`) "immutable" application snapshot to production environment when GitHub release is published; ## Customize Blueprint @@ -189,7 +202,7 @@ Continuos Integration and Delivery is implemented using GitHub Actions. It consi stackID := fmt.Sprintf("blueprint-golang-%s", vsn(app)) stack := awscdk.NewStack(app, jsii.String(stackID), config) ``` -- [ ] update the target stack name at CI/CD workflows [spawn.yml](.github/workflows/spawn.yml), [build.yml](.github/workflows/build.yml) and [carry.yml](.github/workflows/carry.yml) +- [ ] update the target stack name at CI/CD workflows [check-spawn.yml](.github/workflows/check-spawn.yml), [build.yml](.github/workflows/build.yml), [carry.yml](.github/workflows/carry.yml) and [check-clean.yml](.github/workflows/check-clean.yml) ```yaml strategy: matrix: