From 67770abb8456d7add0b826a5692f6e31cf7c8174 Mon Sep 17 00:00:00 2001 From: Hemanth Nakkina Date: Sat, 20 Apr 2024 14:01:46 +0530 Subject: [PATCH] Upload charm before OCI images in publish charm job Currently the publish-charm task uploads the OCI image resources and then the charm. If a charm introduces a new OCI image resource then this workflow wont work as charmhub is not aware of the new resource. Uploading charm first will enable charmhub to understand the new resource. Change tasks to upload charm first and then the OCI image resources. Change-Id: I70de4f19558c62caeaa8821a3bbd9cac1fd96c0d --- roles/charm-publish/tasks/publish.yaml | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/roles/charm-publish/tasks/publish.yaml b/roles/charm-publish/tasks/publish.yaml index d154a275..dd4a5ab8 100644 --- a/roles/charm-publish/tasks/publish.yaml +++ b/roles/charm-publish/tasks/publish.yaml @@ -46,6 +46,22 @@ set_fact: metadata: "{{ metadata_file.content | b64decode | from_yaml }}" + - name: Upload charm to charmhub + register: upload_charm_output + args: + chdir: "{{ zuul.project.src_dir }}" + # TODO: The below command can error out with a message that says + # upload with that digest already exists. This case need to be handled. + # More details https://github.com/canonical/charmcraft/issues/826 + command: charmcraft upload -v --name {{ charm_build_name }} {{ charm_build_name }}.charm + retries: 3 + until: > + ("Revision" in upload_charm_output.stdout) + + - name: Extract Charm revision + set_fact: + charm_revision: "{{ upload_charm_output.stdout | regex_search('Revision ([0-9]+)', '\\1', multiline=True) | first }}" + - name: Upload oci-image to charmhub register: upload_oci_image_output args: @@ -70,22 +86,6 @@ resource_revision_flags: "{{ resource_revision_flags | default('') + ' --resource ' + item.item.key + ':' + (item.stdout | regex_search('Revision ([0-9]+)', '\\1', multiline=True) | first) }}" with_items: "{{ upload_oci_image_output.results }}" - - name: Upload charm to charmhub - register: upload_charm_output - args: - chdir: "{{ zuul.project.src_dir }}" - # TODO: The below command can error out with a message that says - # upload with that digest already exists. This case need to be handled. - # More details https://github.com/canonical/charmcraft/issues/826 - command: charmcraft upload -v --name {{ charm_build_name }} {{ charm_build_name }}.charm - retries: 3 - until: > - ("Revision" in upload_charm_output.stdout) - - - name: Extract Charm revision - set_fact: - charm_revision: "{{ upload_charm_output.stdout | regex_search('Revision ([0-9]+)', '\\1', multiline=True) | first }}" - - name: Release charm register: release_charm_output command: charmcraft release {{ charm_build_name }} --revision {{ charm_revision }} --channel {{ publish_channel }} {{ resource_revision_flags | default("") }}