|
| 1 | +name: Spot GoReleaser |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + RUN_TESTS: |
| 7 | + description: "Run tests?" |
| 8 | + required: true |
| 9 | + default: true |
| 10 | + type: boolean |
| 11 | + |
| 12 | + RUN_BUILD: |
| 13 | + description: "Build the project?" |
| 14 | + required: true |
| 15 | + default: true |
| 16 | + type: boolean |
| 17 | + |
| 18 | + RELEASE_TYPE: |
| 19 | + description: "Type of release" |
| 20 | + required: true |
| 21 | + default: "snapshot" |
| 22 | + type: choice |
| 23 | + options: |
| 24 | + - snapshot |
| 25 | + - full |
| 26 | + |
| 27 | + BRANCH_SELECTOR: |
| 28 | + description: "Branch to build" |
| 29 | + required: false |
| 30 | + default: "feat-spot-ocean" |
| 31 | + |
| 32 | + RELEASE_DESCRIPTION: |
| 33 | + description: "Description of the release" |
| 34 | + required: false |
| 35 | + default: "" |
| 36 | + |
| 37 | +jobs: |
| 38 | + build: |
| 39 | + runs-on: optimized-scale-set |
| 40 | + |
| 41 | + #Fetching source code into the runner |
| 42 | + steps: |
| 43 | + - name: Checkout code |
| 44 | + uses: actions/checkout@v3 |
| 45 | + with: |
| 46 | + ref: ${{ inputs.BRANCH_SELECTOR }} |
| 47 | + fetch-depth: 0 |
| 48 | + fetch-tags: true |
| 49 | + |
| 50 | + - name: Set up Go |
| 51 | + uses: actions/setup-go@v4 |
| 52 | + with: |
| 53 | + go-version: "1.21" |
| 54 | + |
| 55 | + - name: Show Go environment |
| 56 | + run: | |
| 57 | + go version |
| 58 | + go env |
| 59 | +
|
| 60 | + #Tools for code testing |
| 61 | + - name: Install tools |
| 62 | + if: ${{ inputs.RUN_TESTS }} |
| 63 | + run: | |
| 64 | + sudo apt-get update |
| 65 | + sudo apt-get install -y make |
| 66 | +
|
| 67 | + - name: Run tests |
| 68 | + if: ${{ inputs.RUN_TESTS }} |
| 69 | + run: | |
| 70 | + make lint |
| 71 | + make check-all-generated-files-up-to-date |
| 72 | + make unit-test |
| 73 | +
|
| 74 | + #Getting the version of eksctl for tagging the release |
| 75 | + - name: Build native eksctl for tagging |
| 76 | + if: ${{ inputs.RELEASE_TYPE == 'full' && inputs.RUN_BUILD }} |
| 77 | + run: | |
| 78 | + mkdir -p ./dist |
| 79 | + GOOS=linux GOARCH=amd64 go build -v -o dist/eksctl ./cmd/eksctl |
| 80 | + chmod +x dist/eksctl |
| 81 | +
|
| 82 | + - name: Extract release tag from binary |
| 83 | + if: ${{ inputs.RELEASE_TYPE == 'full' && inputs.RUN_BUILD }} |
| 84 | + id: extract_tag |
| 85 | + run: | |
| 86 | + BIN="dist/eksctl" |
| 87 | + if [[ ! -f "$BIN" ]]; then |
| 88 | + echo "Error: eksctl binary not found" |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | +
|
| 92 | + VERSION=$("$BIN" version | cut -d- -f1) |
| 93 | + EKSCTL_VERSION="v$VERSION" |
| 94 | + echo "Extracted release tag: $EKSCTL_VERSION" |
| 95 | +
|
| 96 | + echo "release_tag=$EKSCTL_VERSION" >> $GITHUB_OUTPUT |
| 97 | + echo "EKSCTL_RELEASE_TAG=$EKSCTL_VERSION" >> $GITHUB_ENV |
| 98 | +
|
| 99 | + - name: Create local git tag (required by GoReleaser) |
| 100 | + if: ${{ inputs.RELEASE_TYPE == 'full' && inputs.RUN_BUILD }} |
| 101 | + run: | |
| 102 | + git config user.name "github-actions" |
| 103 | + git config user.email "[email protected]" |
| 104 | + git tag ${{ steps.extract_tag.outputs.release_tag }} |
| 105 | +
|
| 106 | + #The release itself |
| 107 | + #snapshot (only bullding exporting artifacts) |
| 108 | + #full (fully releasing via GitHub Release) |
| 109 | + - name: Run GoReleaser (snapshot or full release) |
| 110 | + if: ${{ inputs.RUN_BUILD }} |
| 111 | + uses: goreleaser/goreleaser-action@v5 |
| 112 | + with: |
| 113 | + version: latest |
| 114 | + args: ${{ inputs.RELEASE_TYPE == 'full' && 'release --clean --parallelism 3' || 'release --snapshot --parallelism 3' }} |
| 115 | + env: |
| 116 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 117 | + GORELEASER_CURRENT_TAG: ${{ steps.extract_tag.outputs.release_tag }} |
| 118 | + RELEASE_DESCRIPTION: ${{ inputs.RELEASE_DESCRIPTION }} |
| 119 | + PRE_RELEASE_ID: dev |
| 120 | + |
| 121 | + #If only building (snapshot) uploading the artifact to the workflow |
| 122 | + - name: Upload built artifacts |
| 123 | + if: ${{ inputs.RUN_BUILD && inputs.RELEASE_TYPE == 'snapshot' }} |
| 124 | + uses: actions/upload-artifact@v4 |
| 125 | + with: |
| 126 | + name: built-artifacts |
| 127 | + path: dist/ |
| 128 | + |
| 129 | + - name: Clean up |
| 130 | + run: | |
| 131 | + rm -rf dist/ |
| 132 | + rm -rf $HOME/.cache/go-build |
| 133 | + rm -rf $GOPATH/pkg/mod |
0 commit comments