|
1 |
| -################################################################## |
2 |
| -# IMPORTANT NOTE # |
3 |
| -# # |
4 |
| -# This file is synced with https://github.com/atomicgo/template # |
5 |
| -# Please make changes there. # |
6 |
| -################################################################## |
| 1 | +# ┌───────────────────────────────────────────────────────────────────┐ |
| 2 | +# │ │ |
| 3 | +# │ IMPORTANT NOTE │ |
| 4 | +# │ │ |
| 5 | +# │ This file is synced with https://github.com/atomicgo/template │ |
| 6 | +# │ │ |
| 7 | +# │ Please apply all changes to the template repository │ |
| 8 | +# │ │ |
| 9 | +# └───────────────────────────────────────────────────────────────────┘ |
7 | 10 |
|
8 | 11 | name: AtomicGo
|
9 | 12 |
|
10 | 13 | on:
|
11 | 14 | push:
|
12 |
| - branches: [main] |
13 |
| - workflow_dispatch: |
| 15 | + branches: |
| 16 | + - main |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + packages: write |
14 | 21 |
|
15 | 22 | jobs:
|
16 |
| - docs: |
17 |
| - if: "!contains(github.event.head_commit.message, 'autoupdate')" |
| 23 | + test: |
| 24 | + name: Test Go Code |
| 25 | + runs-on: ${{ matrix.os }} |
| 26 | + strategy: |
| 27 | + matrix: |
| 28 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 29 | + steps: |
| 30 | + - name: Set up Go |
| 31 | + uses: actions/setup-go@v4 |
| 32 | + with: |
| 33 | + go-version: stable |
| 34 | + |
| 35 | + - name: Check out code into the Go module directory |
| 36 | + uses: actions/checkout@v3 |
| 37 | + |
| 38 | + - name: Get dependencies |
| 39 | + run: go get -v -t -d ./... |
| 40 | + |
| 41 | + - name: Build |
| 42 | + run: go build -v . |
| 43 | + |
| 44 | + - name: Test |
| 45 | + run: go test -coverprofile="coverage.txt" -covermode=atomic -v -p 1 . |
| 46 | + |
| 47 | + - name: Upload coverage to Codecov |
| 48 | + uses: codecov/codecov-action@v3 |
| 49 | + |
| 50 | + build: |
| 51 | + name: Build AtomicGo Package |
18 | 52 | runs-on: ubuntu-latest
|
| 53 | + needs: test |
| 54 | + |
| 55 | + env: |
| 56 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
19 | 58 | steps:
|
20 |
| - - name: Update Docs |
21 |
| - uses: atomicgo/ci@main |
22 |
| - env: |
23 |
| - ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} |
24 |
| - TERM: xterm-256color |
| 59 | + - name: Checkout repository |
| 60 | + uses: actions/checkout@v3 |
| 61 | + with: |
| 62 | + fetch-depth: 0 |
| 63 | + |
| 64 | + - name: Download assets |
| 65 | + run: | |
| 66 | + mkdir -p .templates |
| 67 | + wget https://raw.githubusercontent.com/atomicgo/atomicgo/main/templates/example.gotxt -O .templates/example.gotxt |
| 68 | + wget https://raw.githubusercontent.com/atomicgo/atomicgo/main/templates/readme.md -O .templates/readme.md |
| 69 | +
|
| 70 | + - name: Set up Go |
| 71 | + uses: actions/setup-go@v4 |
| 72 | + with: |
| 73 | + go-version: stable |
| 74 | + |
| 75 | + - name: Install Go tools |
| 76 | + run: | |
| 77 | + go install github.com/robertkrimen/godocdown/godocdown@latest |
| 78 | + go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest |
| 79 | + go install github.com/caarlos0/svu@latest |
| 80 | +
|
| 81 | + - name: Set up Git configuration |
| 82 | + run: | |
| 83 | + REPO_FULLNAME="${{ github.repository }}" |
| 84 | + echo "::group::Setup git" |
| 85 | + git config --global --add safe.directory /github/workspace |
| 86 | +
|
| 87 | + echo "::notice::Login into git" |
| 88 | + git config --global user.email "git@marvinjwendt.com" |
| 89 | + git config --global user.name "MarvinJWendt" |
| 90 | +
|
| 91 | + echo "::notice::Ignore workflow files (we may not touch them)" |
| 92 | + git update-index --assume-unchanged .github/workflows/* |
| 93 | +
|
| 94 | + - name: Generate README.md |
| 95 | + run: | |
| 96 | + echo "::group::Generate README.md" |
| 97 | + FILE=./.github/atomicgo/custom_readme |
| 98 | + INCLUDE_UNEXPORTED=./.github/atomicgo/include_unexported |
| 99 | + if test -f "$FILE"; then |
| 100 | + echo "::notice::.github/custom_readme is present. Not generating a new readme." |
| 101 | + else |
| 102 | + echo "::notice::Running Godocdown" |
| 103 | + $(go env GOPATH)/bin/godocdown -template ./.templates/readme.md >README.md |
| 104 | + echo "::notice::Running gomarkdoc" |
| 105 | + GOMARKDOC_FLAGS="--template-file example=./.templates/example.gotxt" |
| 106 | + if test -f "$INCLUDE_UNEXPORTED"; then |
| 107 | + GOMARKDOC_FLAGS+=" -u" |
| 108 | + fi |
| 109 | +
|
| 110 | + $(go env GOPATH)/bin/gomarkdoc $GOMARKDOC_FLAGS --repository.url "https://github.com/${{ github.repository }}" --repository.default-branch main --repository.path / -e -o README.md . |
| 111 | + fi |
| 112 | + echo "::endgroup::" |
| 113 | +
|
| 114 | + - name: Run custom CI system (bash equivalent of main.go) |
| 115 | + run: | |
| 116 | + echo "::group::Run custom CI system" |
| 117 | + echo "::notice::Counting unit tests" |
| 118 | + unittest_count=$(go test -v -p 1 ./... | tee /dev/tty | grep -c "RUN") |
| 119 | +
|
| 120 | + echo "::notice::Replacing badge in README.md" |
| 121 | + sed -i 's|<img src="https://img.shields.io/badge/Unit_Tests-[^"]*-magenta?style=flat-square"|<img src="https://img.shields.io/badge/Unit_Tests-'$unittest_count'-magenta?style=flat-square"|g' README.md |
| 122 | + echo "::endgroup::" |
| 123 | +
|
| 124 | + - name: Run go mod tidy |
| 125 | + run: | |
| 126 | + echo "::group::Run go mod tidy" |
| 127 | + git checkout go.mod # reset go.mod file |
| 128 | + git checkout go.sum # reset go.sum file |
| 129 | + go mod tidy |
| 130 | + echo "::endgroup::" |
| 131 | +
|
| 132 | + - name: Stage and commit changes |
| 133 | + run: | |
| 134 | + echo "::group::Stage and commit changes" |
| 135 | + git add . |
| 136 | + git commit -m "docs: autoupdate" || true |
| 137 | + echo "::endgroup::" |
| 138 | +
|
| 139 | + - name: Push changes |
| 140 | + run: | |
| 141 | + echo "::notice::Pushing changes to origin" |
| 142 | + git push -u origin main |
| 143 | +
|
| 144 | + - name: Get current version |
| 145 | + id: current_version |
| 146 | + run: | |
| 147 | + echo "current_version=$(svu current)" >> $GITHUB_ENV |
| 148 | + echo "::notice::Current version is $(svu current)" |
| 149 | +
|
| 150 | + - name: Calculate next version |
| 151 | + id: next_version |
| 152 | + run: | |
| 153 | + echo "next_version=$(svu next)" >> $GITHUB_ENV |
| 154 | + echo "::notice::Next version is $(svu next)" |
| 155 | +
|
| 156 | + - name: Check if release is needed |
| 157 | + id: check_release |
| 158 | + run: | |
| 159 | + echo "release_needed=$( [ '${{ env.current_version }}' != '${{ env.next_version }}' ] && echo true || echo false )" >> $GITHUB_ENV |
| 160 | +
|
| 161 | + - name: Create tag |
| 162 | + if: env.release_needed == 'true' |
| 163 | + run: | |
| 164 | + git tag -a ${{ env.next_version }} -m "Release v${{ env.next_version }}" |
| 165 | + git push origin ${{ env.next_version }} |
| 166 | + sleep 5 # sleep for 5 seconds to allow GitHub to process the tag |
| 167 | +
|
| 168 | + - name: Release |
| 169 | + if: env.release_needed == 'true' |
| 170 | + uses: softprops/action-gh-release@v2 |
| 171 | + with: |
| 172 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 173 | + generate_release_notes: true |
| 174 | + tag_name: ${{ env.next_version }} |
0 commit comments