diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a595a3a..9b8f264 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,8 +25,8 @@ on: description: "Create GitHub release" type: boolean default: false - version: - description: "Release version" + ref: + description: "Release version ref" required: false type: string @@ -35,6 +35,8 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref || github.ref }} - uses: actions/cache@v4 with: path: | @@ -54,6 +56,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref || github.ref }} - uses: actions/cache@v4 with: path: | @@ -62,6 +66,12 @@ jobs: key: bazel-${{ hashFiles('common.bazelrc', '.bazelrc', '.bazelversion', 'WORKSPACE', 'MODULE.bazel', 'requirements.txt') }} restore-keys: bazel- - run: bazel/tools/update_version_bzl.sh version.bzl + - name: Read version + id: version + run: echo "value=$(bazelisk run //:version)" >> $GITHUB_OUTPUT + - name: Echo version + run: echo ${{ steps.version.outputs.value }} + - run: bazelisk build --stamp "--platforms=@rules_go//go/toolchain:${{ matrix.os }}_${{ matrix.arch }}" //agent/cmd/agent //tools/nbictl/cmd/nbictl - name: Package binary @@ -87,6 +97,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref || github.ref }} - uses: actions/cache@v4 with: path: | @@ -106,23 +118,26 @@ jobs: needs: [build-and-upload-tools] runs-on: ubuntu-latest if: | - github.event_name == 'workflow_dispatch' && - inputs.create_release == true && - inputs.version != '' - + startsWith( github.ref, 'refs/heads/release-' ) || + (github.event_name == 'workflow_dispatch' && inputs.create_release == true && inputs.ref != '') steps: - uses: actions/checkout@v4 - + with: + ref: ${{ github.event.inputs.ref || github.ref }} - name: Download all artifacts uses: actions/download-artifact@v4 with: pattern: tools-* + - run: bazel/tools/update_version_bzl.sh version.bzl + - name: Read version + id: version + run: echo "value=$(bazelisk run //:version)" >> $GITHUB_OUTPUT - name: Create Release uses: softprops/action-gh-release@v2 with: - tag_name: ${{ inputs.version }} - name: Release ${{ inputs.version }} + tag_name: v${{ steps.version.outputs.value }} + name: Release v${{ steps.version.outputs.value }} # TODO: Change to non-draft after testing. draft: true files: | diff --git a/BUILD b/BUILD index 8127909..36cd77f 100644 --- a/BUILD +++ b/BUILD @@ -20,3 +20,12 @@ gazelle_test( tags = ["manual"], workspace = "//:BUILD", ) + +load("//:version.bzl", "VERSION") + +genrule( + name = "version", + outs = ["print_version.sh"], + cmd = "echo '#!/bin/bash\necho " + VERSION + "' > $@", + executable = True, +) diff --git a/bazel/tools/update_version_bzl.sh b/bazel/tools/update_version_bzl.sh index 9539d8b..5fb677d 100755 --- a/bazel/tools/update_version_bzl.sh +++ b/bazel/tools/update_version_bzl.sh @@ -49,3 +49,5 @@ PATCH = ${git_data[1]}" "$versions_bzl_file_path" sed -i "/^BUILD = /c\\ BUILD = \"${git_data[0]}\"" "$versions_bzl_file_path" + +#FIXME \ No newline at end of file