Skip to content

Commit

Permalink
compatible(release_*.yaml): Create git tags for all snap & charm revi…
Browse files Browse the repository at this point in the history
…sions (#213)

Makes it easier to find git commit for a revision
  • Loading branch information
carlcsaposs-canonical authored Jul 23, 2024
1 parent e3d5fcb commit 9e3a54b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/release_charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
7 changes: 2 additions & 5 deletions .github/workflows/release_snap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
18 changes: 18 additions & 0 deletions python/cli/data_platform_workflows_cli/craft_tools/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9e3a54b

Please sign in to comment.