From 6defc4bbda093555dcc7e25e1de8b12dcb050d42 Mon Sep 17 00:00:00 2001 From: Yannic Date: Thu, 31 Oct 2024 00:34:35 +0100 Subject: [PATCH] [ci] Automatically create release when pushing to main (#9) --- .github/workflows/main.yml | 63 +++++++++++++++++++++++++++++++++++++- MODULE.bazel | 4 +-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8063e80..1db35d8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ env: OPAL_RPC_CREDENTIALS: ${{ secrets.OPAL_RPC_CREDENTIALS }} jobs: - build-all: + check: runs-on: ubuntu-latest steps: @@ -21,3 +21,64 @@ jobs: - name: Build run: bazel build //... + + publish: + runs-on: ubuntu-latest + needs: + - "check" + if: github.ref == 'refs/heads/main' + + steps: + - uses: actions/checkout@v4 + + - name: Create tag + id: "tag" + env: + GIT_AUTHOR_NAME: "EngFlow" + GIT_AUTHOR_EMAIL: "noreply@engflow.com" + GIT_COMMITTER_NAME: "EngFlow" + GIT_COMMITTER_EMAIL: "noreply@engflow.com" + run: | + VERSION="$(date -u '+%Y.%m.%d-%H.%M.%S')" + echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" + + # 1. Download `buildozer` + curl -o "${RUNNER_TEMP}/buildozer" -L "https://github.com/bazelbuild/buildtools/releases/download/v7.3.1/buildozer-linux-amd64" + chmod +x "${RUNNER_TEMP}/buildozer" + + # 2. Update `MODULE.bazel` and commit. + "${RUNNER_TEMP}/buildozer" "set version ${VERSION}" "//MODULE.bazel:engflowapis" + git add "MODULE.bazel" + git commit -m "Release ${VERSION}" + + # 3. Push release tag. + git tag "${VERSION}" "HEAD" + git push origin "${VERSION}" + + # 4. Create release tarball + git archive -o "${RUNNER_TEMP}/archive.tar.gz" "${VERSION}" + + - name: Create GitHub Release + id: "create-release" + uses: actions/create-release@v1 + with: + tag_name: ${{ steps.tag.outputs.version }} + release_name: Release ${{ steps.tag.outputs.version }} + body: | + # EngFlow APIs ${{ steps.tag.outputs.version }} + + To use this module, please add the following to `MODULE.bazel`: + + ```starlark + bazel_dep(name = "engflowapis", version = "${{ steps.tag.outputs.version }}") + ``` + prerelease: true + + - name: Upload Tarball + id: upload-release-asset + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create-release.outputs.upload_url }} + asset_path: ${{ runner.temp }}/archive.tar.gz + asset_name: engflowapis-${{ steps.tag.outputs.version }}.tar.gz + asset_content_type: "application/gzip" diff --git a/MODULE.bazel b/MODULE.bazel index 15d89c8..0020c9a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,19 +1,17 @@ module( name = "engflowapis", - version = "2024.10.16", + version = "HEAD", # Automatically updated by release pipeline. ) bazel_dep( name = "rules_proto", version = "6.0.2", ) - bazel_dep( name = "protobuf", version = "28.2", repo_name = "com_google_protobuf", ) - bazel_dep( name = "googleapis", version = "0.0.0-20240819-fe8ba054a",