|
| 1 | +name: |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | + push: |
| 7 | + paths: |
| 8 | + - cmd/k3s-runner |
| 9 | + - ".github/workflows/**" |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + docker-builds: |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + target_arch: |
| 20 | + - amd64 |
| 21 | + - arm64 |
| 22 | + |
| 23 | + runs-on: ubuntu-latest |
| 24 | + name: Deploy to Docker Image |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v3 |
| 28 | + |
| 29 | + - name: Install Go |
| 30 | + uses: actions/setup-go@v5 |
| 31 | + with: |
| 32 | + go-version: 1.21.5 |
| 33 | + |
| 34 | + - name: Install Task |
| 35 | + uses: arduino/setup-task@v1 |
| 36 | + with: |
| 37 | + version: 3.x |
| 38 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + - name: Install UPX |
| 41 | + run: | |
| 42 | + curl -L0 https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-amd64_linux.tar.xz > upx.tar.xz |
| 43 | + tar -xf upx.tar.xz |
| 44 | + sudo mv upx-4.2.1-amd64_linux/upx /usr/local/bin |
| 45 | +
|
| 46 | +
|
| 47 | + - name: Create Release Tag from branch name |
| 48 | + if: startsWith(github.ref, 'refs/heads/release') |
| 49 | + run: | |
| 50 | + set +e |
| 51 | + RELEASE_TAG=$(echo ${GITHUB_REF#refs/heads/} | sed 's/release-//g') |
| 52 | + echo "$RELEASE_TAG" | grep -i '\-nightly$' |
| 53 | + if [ $? -ne 0 ]; then |
| 54 | + RELEASE_TAG="$RELEASE_TAG-nightly" |
| 55 | + fi |
| 56 | + set -e |
| 57 | +
|
| 58 | + echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV |
| 59 | + echo "OVERRIDE_RELEASE=true" >> $GITHUB_ENV |
| 60 | +
|
| 61 | + - name: Create Release Tag from tag |
| 62 | + if: startsWith(github.ref, 'refs/tags/') |
| 63 | + run: | |
| 64 | + RELEASE_TAG=$(echo ${GITHUB_REF#refs/tags/}) |
| 65 | +
|
| 66 | + echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV |
| 67 | + echo "OVERRIDE_RELEASE=false" >> $GITHUB_ENV |
| 68 | +
|
| 69 | + - name: Build And Release |
| 70 | + env: |
| 71 | + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 72 | + RELEASE_TITLE: "kloudlite-k3s-runner" |
| 73 | + RELEASE_NOTES: "kloudlite k3s runner" |
| 74 | + GOARCH: ${{matrix.target_arch}} |
| 75 | + run: | |
| 76 | + pushd cmd/k3s-runner |
| 77 | +
|
| 78 | + task build |
| 79 | +
|
| 80 | + PRE_RELEASE=$OVERRIDE_RELEASE |
| 81 | +
|
| 82 | + opts=("-R" "${{ github.repository }}") |
| 83 | +
|
| 84 | + release=$(gh release list ${opts[@]} | tail -n +1 | (grep -iE "\s+$RELEASE_TAG\s+" || echo -n "") | awk '{print $3}') |
| 85 | +
|
| 86 | + if [[ -z $release ]]; then |
| 87 | + echo "going to create release, as RELEASE ($RELEASE_TAG) does not exist" |
| 88 | + createOpts="${opts[@]}" |
| 89 | + if [ $PRE_RELEASE = "true" ]; then |
| 90 | + createOpts+=("--prerelease") |
| 91 | + fi |
| 92 | +
|
| 93 | + if ! [[ -z $RELEASE_TITLE ]]; then |
| 94 | + createOpts+=("--title" "'$RELEASE_TITLE'") |
| 95 | + fi |
| 96 | + createOpts+=("--notes" "'$RELEASE_NOTES'") |
| 97 | +
|
| 98 | + echo "creating github release with cmd: \`gh release create $RELEASE_TAG ${createOpts[@]}\` " |
| 99 | + eval gh release create "$RELEASE_TAG" ${createOpts[@]} --generate-notes |
| 100 | + fi |
| 101 | +
|
| 102 | + uploadOpts="${opts[@]}" |
| 103 | + if [ "$OVERRIDE_RELEASE" = "true" ]; then |
| 104 | + uploadOpts+=("--clobber") |
| 105 | + fi |
| 106 | +
|
| 107 | + echo "uploading buillt binary with cmd: \`gh release upload $RELEASE_TAG ${uploadOpts[*]} bin/*\`" |
| 108 | + gh release upload "$RELEASE_TAG" ${uploadOpts[@]} bin/* |
0 commit comments