Skip to content

Commit 33d893c

Browse files
authored
fix(actions): update CI (#2194)
* fix(create-release-pr): use correct ref in action GitHub Actions changed the meaning of `pull_request_target`, so that it now uses the default branch instead of the pull request base, meaning that `GITHUB_HEAD_REF` would always be `main` instead of `release/x.y`. This change checks out the repo at `GITHUB_BASE_REF`, then uses `rev-parse` to determine the name of the branch. See: https://github.blog/changelog/2025-11-07-actions-pull_request_target-and-environment-branch-protections-changes/#what-is-changing * fix(release-action): support uploading multiple charms
1 parent 508d103 commit 33d893c

File tree

7 files changed

+94
-22
lines changed

7 files changed

+94
-22
lines changed

.github/actions/create-cut-pr/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31720,6 +31720,16 @@ class Git {
3172031720
async exec(...args) {
3172131721
return exec.exec("git", args);
3172231722
}
31723+
/**
31724+
* Execute the provided git command, and return the output.
31725+
*/
31726+
async execOutput(...args) {
31727+
const output = await exec.getExecOutput("git", args);
31728+
if (output.exitCode !== 0) {
31729+
throw new Error(`command exited non-zero: ${output.stdout}`);
31730+
}
31731+
return output.stdout;
31732+
}
3172331733
/**
3172431734
* Set a git config value.
3172531735
*/
@@ -31774,6 +31784,13 @@ class Git {
3177431784
}
3177531785
await this.exec("push", ...flags, this.origin, ...branches);
3177631786
}
31787+
/**
31788+
* Run `rev-parse` on the `HEAD`.
31789+
*/
31790+
async revParse() {
31791+
const rev = await this.execOutput("rev-parse", "--abbrev-ref", "HEAD");
31792+
return rev.trim();
31793+
}
3177731794
}
3177831795

3177931796
;// CONCATENATED MODULE: ./src/lib/github/pull-request.ts
@@ -32211,10 +32228,11 @@ async function createCtx(fallback) {
3221132228
}
3221232229
const git = new Git();
3221332230
await git.configUser();
32231+
const refName = await git.revParse();
3221432232
return {
3221532233
octokit,
3221632234
core: core,
32217-
context: Object.assign({ refName: process.env["GITHUB_REF_NAME"] }, github.context),
32235+
context: Object.assign({ refName }, github.context),
3221832236
exec: exec.exec,
3221932237
execOutput: exec.getExecOutput,
3222032238
repo,

.github/actions/create-release-pr/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31720,6 +31720,16 @@ class Git {
3172031720
async exec(...args) {
3172131721
return exec.exec("git", args);
3172231722
}
31723+
/**
31724+
* Execute the provided git command, and return the output.
31725+
*/
31726+
async execOutput(...args) {
31727+
const output = await exec.getExecOutput("git", args);
31728+
if (output.exitCode !== 0) {
31729+
throw new Error(`command exited non-zero: ${output.stdout}`);
31730+
}
31731+
return output.stdout;
31732+
}
3172331733
/**
3172431734
* Set a git config value.
3172531735
*/
@@ -31774,6 +31784,13 @@ class Git {
3177431784
}
3177531785
await this.exec("push", ...flags, this.origin, ...branches);
3177631786
}
31787+
/**
31788+
* Run `rev-parse` on the `HEAD`.
31789+
*/
31790+
async revParse() {
31791+
const rev = await this.execOutput("rev-parse", "--abbrev-ref", "HEAD");
31792+
return rev.trim();
31793+
}
3177731794
}
3177831795

3177931796
;// CONCATENATED MODULE: ./src/lib/github/pull-request.ts
@@ -32211,10 +32228,11 @@ async function createCtx(fallback) {
3221132228
}
3221232229
const git = new Git();
3221332230
await git.configUser();
32231+
const refName = await git.revParse();
3221432232
return {
3221532233
octokit,
3221632234
core: core,
32217-
context: Object.assign({ refName: process.env["GITHUB_REF_NAME"] }, github.context),
32235+
context: Object.assign({ refName }, github.context),
3221832236
exec: exec.exec,
3221932237
execOutput: exec.getExecOutput,
3222032238
repo,

.github/actions/extract-changelog/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31720,6 +31720,16 @@ class Git {
3172031720
async exec(...args) {
3172131721
return exec.exec("git", args);
3172231722
}
31723+
/**
31724+
* Execute the provided git command, and return the output.
31725+
*/
31726+
async execOutput(...args) {
31727+
const output = await exec.getExecOutput("git", args);
31728+
if (output.exitCode !== 0) {
31729+
throw new Error(`command exited non-zero: ${output.stdout}`);
31730+
}
31731+
return output.stdout;
31732+
}
3172331733
/**
3172431734
* Set a git config value.
3172531735
*/
@@ -31774,6 +31784,13 @@ class Git {
3177431784
}
3177531785
await this.exec("push", ...flags, this.origin, ...branches);
3177631786
}
31787+
/**
31788+
* Run `rev-parse` on the `HEAD`.
31789+
*/
31790+
async revParse() {
31791+
const rev = await this.execOutput("rev-parse", "--abbrev-ref", "HEAD");
31792+
return rev.trim();
31793+
}
3177731794
}
3177831795

3177931796
;// CONCATENATED MODULE: ./src/lib/github/pull-request.ts
@@ -32211,10 +32228,11 @@ async function createCtx(fallback) {
3221132228
}
3221232229
const git = new Git();
3221332230
await git.configUser();
32231+
const refName = await git.revParse();
3221432232
return {
3221532233
octokit,
3221632234
core: core,
32217-
context: Object.assign({ refName: process.env["GITHUB_REF_NAME"] }, github.context),
32235+
context: Object.assign({ refName }, github.context),
3221832236
exec: exec.exec,
3221932237
execOutput: exec.getExecOutput,
3222032238
repo,

.github/workflows/create-release-pr.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ jobs:
1515
runs-on: "ubuntu-latest"
1616
if: github.event_name == 'push' || github.event.pull_request.merged == true
1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v6
19+
with:
20+
ref: ${{ github.base_ref }}
1921
- uses: ./.github/actions/create-release-pr
2022
with:
2123
github-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,18 @@ jobs:
125125
- name: Get charm path
126126
id: post-build
127127
run: |
128-
CHARM_PATH=$(ls -1 charms/${{ matrix.charm-kind }}-charm/*.charm)
128+
CHARM_DIR='charms/${{ matrix.charm-kind }}-charm'
129129
130-
if [ $(echo "$CHARM_PATH" | wc -l) -ne 1 ]; then
131-
echo "Multiple charm artifacts found:"
132-
echo "$CHARM_PATH"
133-
exit 1
134-
fi
130+
# Concatenate charm paths into a single line with commas
131+
BUILT_CHARM_PATHS=$(ls -1 $CHARM_DIR/*.charm | xargs -L1 basename | paste -sd ',' -)
135132
136-
echo "charm-path=$CHARM_PATH" | tee -a "$GITHUB_OUTPUT"
137-
echo "charm-dir=$(dirname $CHARM_PATH)" | tee -a "$GITHUB_OUTPUT"
138-
echo "charm-name=$(basename $CHARM_PATH)" | tee -a "$GITHUB_OUTPUT"
133+
echo "charm-dir=$CHARM_DIR" | tee -a "$GITHUB_OUTPUT"
134+
echo "built-charm-path=$BUILT_CHARM_PATHS" | tee -a "$GITHUB_OUTPUT"
139135
- name: Save charm artifact
140136
uses: actions/upload-artifact@v4
141137
with:
142-
name: juju-dashboard-${{ matrix.charm-kind }}.charm
143-
path: ${{ steps.post-build.outputs.charm-path }}
138+
name: juju-dashboard-${{ matrix.charm-kind }}
139+
path: ${{ steps.post-build.outputs.charm-dir }}/*.charm
144140
- name: Create new tracks, if required
145141
run: |
146142
track='${{ needs.pre-release.outputs.track }}'
@@ -165,7 +161,7 @@ jobs:
165161
github-token: "${{ secrets.GITHUB_TOKEN }}"
166162
channel: "${{ needs.pre-release.outputs.channel }}"
167163
charm-path: "${{ steps.post-build.outputs.charm-dir }}"
168-
built-charm-path: "${{ steps.post-build.outputs.charm-name }}"
164+
built-charm-path: "${{ steps.post-build.outputs.built-charm-path }}"
169165
upload-image: true
170166
pull-image: false
171167
charmcraft-channel: latest/stable
@@ -237,12 +233,12 @@ jobs:
237233
- name: "Download k8s charm artifact"
238234
uses: actions/download-artifact@v4
239235
with:
240-
name: juju-dashboard-k8s.charm
236+
name: juju-dashboard-k8s
241237
path: release-artifacts
242238
- name: "Download machine charm artifact"
243239
uses: actions/download-artifact@v4
244240
with:
245-
name: juju-dashboard-machine.charm
241+
name: juju-dashboard-machine
246242
path: release-artifacts
247243

248244
- name: "Create release"

actions/src/lib/git.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ export default class Git {
3636
return exec.exec("git", args);
3737
}
3838

39+
/**
40+
* Execute the provided git command, and return the output.
41+
*/
42+
private async execOutput(...args: string[]): Promise<string> {
43+
const output = await exec.getExecOutput("git", args);
44+
45+
if (output.exitCode !== 0) {
46+
throw new Error(`command exited non-zero: ${output.stdout}`);
47+
}
48+
49+
return output.stdout;
50+
}
51+
3952
/**
4053
* Set a git config value.
4154
*/
@@ -117,4 +130,12 @@ export default class Git {
117130

118131
await this.exec("push", ...flags, this.origin, ...branches);
119132
}
133+
134+
/**
135+
* Run `rev-parse` on the `HEAD`.
136+
*/
137+
async revParse(): Promise<string> {
138+
const rev = await this.execOutput("rev-parse", "--abbrev-ref", "HEAD");
139+
return rev.trim();
140+
}
120141
}

actions/src/lib/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ export async function createCtx(fallback?: {
5454
const git = new Git();
5555
await git.configUser();
5656

57+
const refName = await git.revParse();
58+
5759
return {
5860
octokit,
5961
core,
60-
context: Object.assign(
61-
{ refName: process.env["GITHUB_REF_NAME"] },
62-
github.context,
63-
),
62+
context: Object.assign({ refName }, github.context),
6463
exec: exec.exec,
6564
execOutput: exec.getExecOutput,
6665
repo,

0 commit comments

Comments
 (0)