From 8e8b9e928b2977cd5e4d28c77a5887a13f8ea39e Mon Sep 17 00:00:00 2001 From: yuri-1987 <27512519+yuri-1987@users.noreply.github.com> Date: Thu, 20 Jan 2022 18:05:56 +0200 Subject: [PATCH] init release --- .github/workflows/lint.yml | 19 ++++++++++ .golangci.yml | 28 +++++++++++++++ README.md | 71 ++++++++++++++++++++++++++++++++++++++ release.sh | 19 ++++++++++ 4 files changed, 137 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .golangci.yml create mode 100644 README.md create mode 100755 release.sh diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..c1ec581 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,19 @@ +name: Lint + +on: + pull_request: + + +jobs: + golangci: + name: 🔍 golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.43 + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + skip-go-installation: false \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..18153c2 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,28 @@ +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - errcheck + - gofmt + - gosec + - gosimple + - govet + - ineffassign + - misspell + - prealloc + - staticcheck + - structcheck + - typecheck + - unconvert + - unused + - varcheck + +run: + # default concurrency is a available CPU number. + # concurrency: 2 # explicitly omit this value to fully utilize available resources. + timeout: 2m + modules-download-mode: readonly + deadline: 5m + issues-exit-code: 0 + tests: false \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d344d49 --- /dev/null +++ b/README.md @@ -0,0 +1,71 @@ +# gh-deploy +A `gh` cli extension to approve or reject pending deployments that are waiting for review. + +## Installation + +Installation requires a minimum version (2.0.0) of the the Github CLI to support extensions. + +1. Install the `gh cli` - see the [installation/upgrade instructions](https://github.com/cli/cli#installation) + +2. Install this extension: +```sh +gh extension install yuri-1987/gh-deploy +``` + +## Usage +```sh +gh deploy --help + +Usage: + gh-deploy [OPTIONS] + +Application Options: + -r, --repo= Github reposiory name including owner + -e, --env= Github environment name + -i, --run-id= Github Action run id to approve + --approve Approve deployment + --reject Reject deployment + +Help Options: + -h, --help Show this help message +``` +To **approve** pending deployment by run-id: +```sh +gh deploy --env prod --run-id 1723641358 --repo "yuri-1987/tf-iac" --approve +``` +To **reject** pending deployment by run-id: +```sh +gh deploy --env prod --run-id 1723641358 --repo "yuri-1987/tf-iac" --reject +``` + +## Use cases +Set environment protection rules for your Github repository, ie. `prod` environment requires a review from your team members. + +send them a slack message with the details of the deployment via github action. + +**_workflow snippet:_** +```yaml +deployment_job_name: + runs-on: ubuntu-latest + steps: + - name: send slack message for approval + uses: act10ns/slack@v1.5.0 + with: + status: "tf prod waiting for approval" + channel: '#deployments' + message: | + *Terraform Apply for Production env in `${{ github.repository }}` is pending approval* + Review requested by ${{ github.actor }} + Please review it here: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.run_id }}> + To *approve*, run: + ``` + gh deploy --env prod --run-id ${{ github.run_id }} --repo "${{ github.repository }}" --approve + ``` + To *reject*, run: + ``` + gh deploy --env prod --run-id ${{ github.run_id }} --repo "${{ github.repository }}" --reject + ``` + <{{diffUrl}}|Link to PR diff in branch: `{{branch}}`> +``` + + diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..9cdf4de --- /dev/null +++ b/release.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +tag="${1}" + +if [ "${tag}" == "" ]; then + echo "tag argument required" + exit 1 +fi + +rm -rf dist +GOOS=darwin GOARCH=amd64 go build -o "dist/darwin-x86_64-${tag}" +GOOS=darwin GOARCH=arm64 go build -o "dist/darwin-arm64-${tag}" +GOOS=linux GOARCH=386 go build -o "dist/linux-i386-${tag}" +GOOS=linux GOARCH=amd64 go build -o "dist/linux-x86_64-${tag}" +GOOS=windows GOARCH=386 go build -o "dist/windows-i386-${tag}" +GOOS=windows GOARCH=amd64 go build -o "dist/windows-x86_64-${tag}" + +gh release create "$tag" ./dist/* --title="${tag}" --notes "${tag}" \ No newline at end of file