aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows
diff options
context:
space:
mode:
Diffstat (limited to '.github/workflows')
-rw-r--r--.github/workflows/main.yml103
1 files changed, 103 insertions, 0 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..6614aae
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,103 @@
+name: build
+
+on: [pull_request, push]
+
+jobs:
+ linux:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ go-version: [1.18.x]
+
+ steps:
+ - name: Set up Go
+ uses: actions/setup-go@v2
+ with:
+ go-version: ${{ matrix.go-version }}
+ id: go
+
+ - name: Set up Go modules cache
+ uses: actions/cache@v2
+ env:
+ cache-name: cache-go-modules
+ with:
+ path: ~/go/pkg/mod
+ key: ${{ runner.os }}-go${{ matrix.go-version }}-build-${{ hashFiles('**/go.sum') }}
+ restore-keys: |
+ ${{ runner.os }}-go${{ matrix.go-version }}-build-${{ env.cache-name }}-
+ ${{ runner.os }}-go${{ matrix.go-version }}-build-
+ ${{ runner.os }}-go${{ matrix.go-version }}-
+
+ - name: Check out code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Run tests
+ run: go test ./...
+
+ - name: Tag new version
+ if: github.ref == 'refs/heads/master' && github.event_name == 'push'
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ set -euxo pipefail
+ next_version () {
+ local current
+ local impact
+ local MAJOR
+ local MINOR
+ local PATCH
+ local parts
+ impact="$1"
+ if [ -z "$1" ]
+ then
+ impact="patch"
+ fi
+ current=$(git tag | sort -r | grep "^[0-9]*\.[0-9]*\.[0-9]" | sort -t "." -k1,1nr -k2,2nr -k3,3nr | head -1 2> /dev/null) || true
+ if [[ -z "$current" ]]; then
+ current='0.0.0'
+ fi
+ parts=(${current//./ })
+ MAJOR=${parts[0]}
+ MINOR=${parts[1]}
+ PATCH=${parts[2]}
+ case "$impact" in
+ major)
+ ((MAJOR+=1))
+ ;;
+ minor)
+ ((MINOR+=1))
+ ;;
+ patch)
+ ((PATCH+=1))
+ ;;
+ esac
+ echo "$MAJOR.$MINOR.$PATCH"
+ }
+ tag_and_release () {
+ local commit
+ commit=$(git rev-parse HEAD)
+ local next
+ if [[ -z "$(git describe --contains "$commit" 2>/dev/null)" ]]; then
+ next="$(next_version "$1")"
+ git tag "$next"
+ git config user.name github-actions
+ git config user.email github-actions@github.com
+ git push --tags
+ echo "RELEASE_TAG=$next" >> $GITHUB_ENV
+ fi
+ }
+
+ git fetch --all --tags
+ tag_and_release patch
+
+ - name: Release
+ if: github.ref == 'refs/heads/master' && github.event_name == 'push'
+ uses: goreleaser/goreleaser-action@v2
+ with:
+ version: latest
+ args: release --rm-dist
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ GOPATH: ${{ env.GOPATH }}