-
Notifications
You must be signed in to change notification settings - Fork 24
183 lines (178 loc) · 7.07 KB
/
Copy pathpublish_charm.yaml
File metadata and controls
183 lines (178 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.
name: Publish charm
on:
workflow_call:
inputs:
channel:
type: string
required: false
description: 'Destination Channel'
charmcraft-channel:
description: Charmcraft channel to use for publishing the charm and resources
type: string
default: latest/stable
force-publish:
description: Evaluate the detection of changes different from documentation to True
type: boolean
default: false
identifier:
type: string
description: >-
The matching integration test workflow job identifier, see identifier in the integration test workflow input.
default: ""
integration-test-workflow-file:
description: The filename of the integration test workflow file.
type: string
default: "integration_test.yaml"
publish-docs:
type: boolean
description: >-
Whether to draft publish the documentation to Discourse.
If set to false, the documentation will not be published.
default: false
publish-libs:
type: boolean
description: >-
Whether to release charm libraries.
If set to false, the libraries will not be released.
default: true
resource-mapping:
type: string
description: >-
Associate rock image names with corresponding resource names specified in the charm metadata.
If not defined, the suffix '-image' to the rock image name will be append.
For instance, a rock image named 'my-rock' will be uploaded as the charm OCI resource named 'my-rock-image'.
default: "{}"
tag-prefix:
type: string
required: false
description: |
Tag prefix, useful when bundling multiple charms in the same repo.
workflow-run-id:
description: >-
Use the newly built charms and images in this workflow run as the new version to upload.
If these are not provided, the system will default to using charms and rocks from the most
recent integration test that matches the git tree ID.
type: string
default: ""
working-directory:
type: string
description: The working directory for jobs
default: "./"
env:
REGISTRY: ghcr.io
OWNER: ${{ github.repository_owner }}
CHARMCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS: "true"
ROCKCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS: "true"
jobs:
select-channel:
runs-on: ubuntu-latest
outputs:
destination-channel: ${{ steps.select-channel.outputs.name }}
steps:
- name: Select charmhub channel
uses: canonical/charming-actions/channel@2.7.0
id: select-channel
continue-on-error: true
plan:
name: Get plan
runs-on: ubuntu-latest
outputs:
plan: ${{ steps.get-plan.outputs.plan }}
run-id: ${{ steps.get-plan.outputs.run-id }}
has-code-changes: ${{ steps.changes.outputs.has_code_changes }}
steps:
- name: Get plan
uses: canonical/operator-workflows/internal/get-plan@main
id: get-plan
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ${{ inputs.working-directory }}
workflow-file: ${{ inputs.integration-test-workflow-file }}
workflow-run-id: ${{ inputs.workflow-run-id }}
identifier: ${{ inputs.identifier }}
- uses: actions/checkout@v6.0.3
with:
fetch-depth: 0
- name: Find changes
id: changes
run: |
if [[ "${{ inputs.force-publish }}" == "true" ]]; then
echo "has_code_changes=True"
exit 0
fi
CHANGED_FILES=$(git diff --name-only "${{ github.event.before }}" "${{ github.event.after }}")
CODE_FILE_CHANGES=$(echo "$CHANGED_FILES" | grep -v "\.md$" | grep -v "^terraform" | wc -l)
echo "has_code_changes=$([[ $CODE_FILE_CHANGES -eq "0" ]] && echo 'False' || echo 'True')" >> $GITHUB_OUTPUT
publish-charm:
name: Publish charm to ${{ inputs.channel || needs.select-channel.outputs.destination-channel }}
runs-on: ubuntu-latest
needs: [ plan, select-channel ]
if: ${{ github.repository == 'canonical/operator-workflows' || needs.plan.outputs.has-code-changes == 'True' }}
outputs:
charm-directory: ${{ steps.publish.outputs.charm-directory }}
steps:
- uses: actions/checkout@v6.0.3
- run: sudo snap install charmcraft --channel ${{ inputs.charmcraft-channel }} --classic
# required to use skopeo embedded within rockcraft - otherwise a docker error
# "io: read/write on closed pipe" will happen
- run: sudo snap install rockcraft --classic
- uses: canonical/operator-workflows/internal/publish@main
id: publish
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
charmhub-token: ${{ secrets.CHARMHUB_TOKEN }}
plan: ${{ needs.plan.outputs.plan }}
resource-mapping: ${{ inputs.resource-mapping }}
working-directory: ${{ inputs.working-directory }}
run-id: ${{ needs.plan.outputs.run-id }}
- name: Change directory
run: |
TEMP_DIR=$(mktemp -d)
cp -rp ./${{ steps.publish.outputs.charm-directory }}/. $TEMP_DIR
rm -rf .* * || :
cp -rp $TEMP_DIR/. .
rm -rf $TEMP_DIR
ls -lah
- name: Add version file to charm
run: |
sudo apt-get update && sudo apt-get install -y zip
echo "${GITHUB_SHA::8}" > version
IFS=',' read -ra CHARM_FILES <<< "${{ steps.publish.outputs.charms }}"
for charm_file in "${CHARM_FILES[@]}"; do
charm_file=$(echo "$charm_file" | xargs)
if ! zipinfo -1 "$charm_file" | grep -qx "version"; then
zip -u "$charm_file" version
fi
done
rm version
- name: Upload charm to charmhub
uses: canonical/charming-actions/upload-charm@2.7.0
with:
built-charm-path: ${{ steps.publish.outputs.charms }}
charmcraft-channel: ${{ inputs.charmcraft-channel }}
credentials: ${{ secrets.CHARMHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
channel: ${{ inputs.channel || needs.select-channel.outputs.destination-channel }}
tag-prefix: ${{ inputs.tag-prefix }}
upload-image: false
release-charm-libs:
name: Release charm libs
runs-on: ubuntu-24.04
if: ${{ inputs.publish-libs && needs.plan.outputs.has-code-changes == 'True' }}
needs: [ plan, publish-charm ]
steps:
- uses: actions/checkout@v6.0.3
- name: Change directory
run: |
TEMP_DIR=$(mktemp -d)
cp -rp ./${{ needs.publish-charm.outputs.charm-directory }}/. $TEMP_DIR
rm -rf .* * || :
cp -rp $TEMP_DIR/. .
rm -rf $TEMP_DIR
- uses: canonical/charming-actions/release-libraries@2.7.0
name: Release libs
with:
credentials: ${{ secrets.CHARMHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}