|
| 1 | +name: Release Cron |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 8 * * 1' # Every Monday at 08:00 UTC |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + check: |
| 13 | + name: Check for Changes |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + should_release: ${{ steps.check.outputs.should_release }} |
| 17 | + next_version: ${{ steps.check.outputs.next_version }} |
| 18 | + steps: |
| 19 | + - name: Checkout Into Source Code |
| 20 | + uses: actions/checkout@v7 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Check diff and compute next version |
| 25 | + id: check |
| 26 | + run: | |
| 27 | + LATEST_TAG=$(git tag --sort=-version:refname | head -1) |
| 28 | +
|
| 29 | + if [ -z "$LATEST_TAG" ]; then |
| 30 | + echo "No tags found, cannot determine next version" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | +
|
| 34 | + echo "Latest tag: $LATEST_TAG" |
| 35 | +
|
| 36 | + if git diff "${LATEST_TAG}..HEAD" --quiet; then |
| 37 | + echo "No changes since ${LATEST_TAG}, skipping release" |
| 38 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 39 | + echo "## No release needed" >> $GITHUB_STEP_SUMMARY |
| 40 | + echo "No changes since ${LATEST_TAG}." >> $GITHUB_STEP_SUMMARY |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | +
|
| 44 | + VERSION_NUMBER=${LATEST_TAG#v} |
| 45 | + MAJOR=$(echo $VERSION_NUMBER | cut -d. -f1) |
| 46 | + MINOR=$(echo $VERSION_NUMBER | cut -d. -f2) |
| 47 | + PATCH=$(echo $VERSION_NUMBER | cut -d. -f3) |
| 48 | + NEXT_PATCH=$((PATCH + 1)) |
| 49 | + NEXT_VERSION="v${MAJOR}.${MINOR}.${NEXT_PATCH}" |
| 50 | +
|
| 51 | + echo "Next version: $NEXT_VERSION" |
| 52 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 53 | + echo "next_version=${NEXT_VERSION}" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + tests: |
| 56 | + name: Run Unit Tests |
| 57 | + needs: check |
| 58 | + if: needs.check.outputs.should_release == 'true' |
| 59 | + runs-on: ubuntu-latest |
| 60 | + steps: |
| 61 | + - name: Checkout Into Source Code |
| 62 | + uses: actions/checkout@v7 |
| 63 | + |
| 64 | + - name: Set up Go |
| 65 | + uses: actions/setup-go@v7 |
| 66 | + with: |
| 67 | + go-version-file: go.mod |
| 68 | + |
| 69 | + - name: Lint code |
| 70 | + uses: golangci/golangci-lint-action@v9 |
| 71 | + |
| 72 | + - name: Run Unit Tests |
| 73 | + run: | |
| 74 | + export CGO_ENABLED=0 |
| 75 | + go version |
| 76 | + go run github.com/onsi/ginkgo/v2/ginkgo --skip-package=integration ./... |
| 77 | +
|
| 78 | + build-and-release: |
| 79 | + name: Build and Release |
| 80 | + needs: [check, tests] |
| 81 | + if: needs.check.outputs.should_release == 'true' |
| 82 | + runs-on: ubuntu-latest |
| 83 | + steps: |
| 84 | + - name: Checkout Into Source Code |
| 85 | + uses: actions/checkout@v7 |
| 86 | + with: |
| 87 | + fetch-depth: 0 |
| 88 | + |
| 89 | + - name: Set up Go |
| 90 | + uses: actions/setup-go@v7 |
| 91 | + with: |
| 92 | + go-version-file: go.mod |
| 93 | + |
| 94 | + - name: Set version variables |
| 95 | + id: version |
| 96 | + run: | |
| 97 | + VERSION="${{ needs.check.outputs.next_version }}" |
| 98 | + VERSION_NUMBER=${VERSION#v} |
| 99 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 100 | + echo "VERSION_NUMBER=$VERSION_NUMBER" >> $GITHUB_OUTPUT |
| 101 | + echo "Building version: $VERSION (number: $VERSION_NUMBER)" |
| 102 | +
|
| 103 | + - name: Create Tag |
| 104 | + run: | |
| 105 | + git config user.name "github-actions[bot]" |
| 106 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 107 | + git tag -a "${{ steps.version.outputs.VERSION }}" -m "Release ${{ steps.version.outputs.VERSION }}" |
| 108 | + git push origin "${{ steps.version.outputs.VERSION }}" |
| 109 | +
|
| 110 | + - name: Build for Linux |
| 111 | + run: | |
| 112 | + echo "Building Storage CLI for Linux" |
| 113 | + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=${{ steps.version.outputs.VERSION_NUMBER }}" \ |
| 114 | + -o "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-linux-amd64" |
| 115 | + echo "### Linux amd64 Build Checksums" >> $GITHUB_STEP_SUMMARY |
| 116 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 117 | + sha1sum "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-linux-amd64" >> $GITHUB_STEP_SUMMARY |
| 118 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 119 | + GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "-X main.version=${{ steps.version.outputs.VERSION_NUMBER }}" \ |
| 120 | + -o "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-linux-arm64" |
| 121 | + echo "### Linux arm64 Build Checksums" >> $GITHUB_STEP_SUMMARY |
| 122 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 123 | + sha1sum "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-linux-arm64" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 125 | +
|
| 126 | + - name: Build for macOS |
| 127 | + run: | |
| 128 | + echo "Building Storage CLI for macOS" |
| 129 | + GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=${{ steps.version.outputs.VERSION_NUMBER }}" \ |
| 130 | + -o "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-darwin-amd64" |
| 131 | + echo "### macOS amd64 Build Checksums" >> $GITHUB_STEP_SUMMARY |
| 132 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 133 | + sha1sum "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-darwin-amd64" >> $GITHUB_STEP_SUMMARY |
| 134 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 135 | + GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "-X main.version=${{ steps.version.outputs.VERSION_NUMBER }}" \ |
| 136 | + -o "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-darwin-arm64" |
| 137 | + echo "### macOS arm64 Build Checksums" >> $GITHUB_STEP_SUMMARY |
| 138 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 139 | + sha1sum "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-darwin-arm64" >> $GITHUB_STEP_SUMMARY |
| 140 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 141 | +
|
| 142 | + - name: Build for Windows |
| 143 | + run: | |
| 144 | + echo "Building Storage CLI for Windows" |
| 145 | + GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=${{ steps.version.outputs.VERSION_NUMBER }}" \ |
| 146 | + -o "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-windows-amd64.exe" |
| 147 | + echo "### Windows Build Checksums" >> $GITHUB_STEP_SUMMARY |
| 148 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 149 | + sha1sum "storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-windows-amd64.exe" >> $GITHUB_STEP_SUMMARY |
| 150 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 151 | +
|
| 152 | + - name: Create Github Release |
| 153 | + uses: ncipollo/release-action@v1 |
| 154 | + with: |
| 155 | + tag: ${{ steps.version.outputs.VERSION }} |
| 156 | + name: Release ${{ steps.version.outputs.VERSION }} |
| 157 | + body: Release ${{ steps.version.outputs.VERSION }} |
| 158 | + artifacts: | |
| 159 | + storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-linux-amd64 |
| 160 | + storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-linux-arm64 |
| 161 | + storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-darwin-amd64 |
| 162 | + storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-darwin-arm64 |
| 163 | + storage-cli-${{ steps.version.outputs.VERSION_NUMBER }}-windows-amd64.exe |
| 164 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 165 | + draft: true # for testing, TODO: change to false |
| 166 | + makeLatest: true |
| 167 | + generateReleaseNotes: true |
0 commit comments