From 9e3a54bc14e015cc1a5e793370f613daa0a71ff0 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Tue, 23 Jul 2024 13:04:03 +0000 Subject: [PATCH] compatible(release_*.yaml): Create git tags for all snap & charm revisions (#213) Makes it easier to find git commit for a revision --- .github/workflows/release_charm.yaml | 7 ++----- .github/workflows/release_snap.yaml | 7 ++----- .../craft_tools/release.py | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release_charm.yaml b/.github/workflows/release_charm.yaml index 57426a23..5f5f4021 100644 --- a/.github/workflows/release_charm.yaml +++ b/.github/workflows/release_charm.yaml @@ -71,7 +71,7 @@ jobs: merge-multiple: true - name: Upload & release charm id: release - run: release-charm --directory='${{ inputs.path-to-charm-directory }}' --channel='${{ inputs.channel }}' + run: release-charm --directory='${{ inputs.path-to-charm-directory }}' --channel='${{ inputs.channel }}' --create-release-tags='${{ inputs.create-github-release }}' env: CHARMCRAFT_AUTH: ${{ secrets.charmhub-token }} - name: Upload charmcraft logs @@ -83,9 +83,6 @@ jobs: if-no-files-found: error - name: Create GitHub release if: ${{ inputs.create-github-release }} - run: | - git tag '${{ steps.release.outputs.release_tag }}' - git push origin '${{ steps.release.outputs.release_tag }}' - gh release create '${{ steps.release.outputs.release_tag }}' --verify-tag --generate-notes --title '${{ steps.release.outputs.release_title }}' --notes-file release_notes.txt + run: gh release create '${{ steps.release.outputs.release_tag }}' --verify-tag --generate-notes --title '${{ steps.release.outputs.release_title }}' --notes-file release_notes.txt env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_snap.yaml b/.github/workflows/release_snap.yaml index c31aafdb..236032fb 100644 --- a/.github/workflows/release_snap.yaml +++ b/.github/workflows/release_snap.yaml @@ -74,7 +74,7 @@ jobs: merge-multiple: true - name: Upload & release snap id: release - run: release-snap --directory='${{ inputs.path-to-snap-project-directory }}' --channel='${{ inputs.channel }}' + run: release-snap --directory='${{ inputs.path-to-snap-project-directory }}' --channel='${{ inputs.channel }}' --create-release-tags='${{ inputs.create-github-release }}' env: SNAPCRAFT_STORE_AUTH: candid SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.snap-store-token }} @@ -87,9 +87,6 @@ jobs: if-no-files-found: error - name: Create GitHub release if: ${{ inputs.create-github-release }} - run: | - git tag '${{ steps.release.outputs.release_tag }}' - git push origin '${{ steps.release.outputs.release_tag }}' - gh release create '${{ steps.release.outputs.release_tag }}' --verify-tag --generate-notes --title '${{ steps.release.outputs.release_title }}' --notes-file release_notes.txt + run: gh release create '${{ steps.release.outputs.release_tag }}' --verify-tag --generate-notes --title '${{ steps.release.outputs.release_title }}' --notes-file release_notes.txt env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/python/cli/data_platform_workflows_cli/craft_tools/release.py b/python/cli/data_platform_workflows_cli/craft_tools/release.py index c930117e..7fc24702 100644 --- a/python/cli/data_platform_workflows_cli/craft_tools/release.py +++ b/python/cli/data_platform_workflows_cli/craft_tools/release.py @@ -42,6 +42,7 @@ def snap(): parser = argparse.ArgumentParser() parser.add_argument("--directory", required=True) parser.add_argument("--channel", required=True) + parser.add_argument("--create-release-tags", required=True) args = parser.parse_args() directory = pathlib.Path(args.directory) @@ -64,6 +65,14 @@ class Revision: logging.info(f"Uploaded snap {revision=} {architecture=}") revisions.append(Revision(value=revision, architecture=architecture)) + if json.loads(args.create_release_tags) is not True: + return + logging.info("Pushing git tag(s)") + # Create git tags + for revision in revisions: + tag = f"rev{revision.value}" + subprocess.run(["git", "tag", tag], check=True) + subprocess.run(["git", "push", "origin", tag], check=True) # Output GitHub release info release_tag = f"rev{max(revision.value for revision in revisions)}" github_actions.output["release_tag"] = release_tag @@ -142,6 +151,7 @@ def charm(): parser = argparse.ArgumentParser() parser.add_argument("--directory", required=True) parser.add_argument("--channel", required=True) + parser.add_argument("--create-release-tags", required=True) args = parser.parse_args() directory = pathlib.Path(args.directory) @@ -197,6 +207,14 @@ def charm(): command += ["--resource", f"{oci.resource_name}:{oci.revision}"] run(command) + if json.loads(args.create_release_tags) is not True: + return + # Create git tags + logging.info("Pushing git tag(s)") + for revision in charm_revisions: + tag = f"rev{revision}" + subprocess.run(["git", "tag", tag], check=True) + subprocess.run(["git", "push", "origin", tag], check=True) # Output GitHub release info release_tag = f"rev{max(charm_revisions)}" github_actions.output["release_tag"] = release_tag