-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Simon Aronsson <[email protected]>
- Loading branch information
Showing
15 changed files
with
45,695 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,12 @@ | |
"author": "Kenneth Koski <[email protected]>", | ||
"license": "GPL-3.0-only", | ||
"scripts": { | ||
"build": "npm run build:upload-charm && npm run build:upload-bundle && npm run build:channel && npm run build:check-libraries && npm run build:release-charm && npm run build:release-libraries", | ||
"build": "npm run build:upload-charm && npm run build:upload-bundle && npm run build:channel && npm run build:check-libraries && npm run build:promote-charm && npm run build:release-charm && npm run build:release-libraries", | ||
"build:upload-bundle": "ncc build src/entries/upload-bundle.ts -o dist/upload-bundle", | ||
"build:upload-charm": "ncc build src/entries/upload-charm.ts -o dist/upload-charm", | ||
"build:channel": "ncc build src/entries/channel.ts -o dist/channel -d", | ||
"build:check-libraries": "ncc build src/entries/check-libraries.ts -o dist/check-libraries", | ||
"build:promote-charm": "ncc build src/entries/promote-charm.ts -o dist/promote-charm", | ||
"build:release-charm": "ncc build src/entries/release-charm.ts -o dist/release-charm", | ||
"build:release-libraries": "ncc build src/entries/release-libraries.ts -o dist/release-libraries", | ||
"test": "jest", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# canonical/charming-actions/promote-charm | ||
|
||
This action is used to promote an already uploaded charm to a different channel in charmhub. It is designed to be manually triggered with the inputs. The promotion involves all the existing bases for the charm. | ||
## Usage | ||
|
||
```yaml | ||
name: Promote charm from a specific track and channel | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
destination-channel: | ||
description: 'Destination Channel' | ||
required: true | ||
origin-channel: | ||
description: 'Origin Channel' | ||
required: true | ||
|
||
# for multi charm repo | ||
charm-name: | ||
description: 'Charm Name' | ||
required: true | ||
jobs: | ||
promote-charm: | ||
name: Promote charm | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Release charm to channel | ||
uses: canonical/charming-actions/promote-charm | ||
with: | ||
credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
destination-channel: ${{ github.event.inputs.destination-channel }} | ||
origin-channel: ${{ github.event.inputs.origin-channel }} | ||
|
||
# for multi charm repo | ||
charm-path: charms/${{ github.event.inputs.charm-name }} | ||
``` | ||
In multi charm repo, you would also need to provide the charm path; this is necessary to correctly extract the charm metadata for the specific charm you are releasing. By convention, it should be the same the name of the charm. The example yaml provided above should work for must multi charm repo setup. | ||
## API | ||
### Inputs | ||
| Key | Description | Required | | ||
| -------------------- | ------------------------------------------------------------------------------------------------------- | -------- | | ||
| `credentials` | Credentials [exported](https://juju.is/docs/sdk/remote-env-auth) using `charmcraft login --export`. | ✔️ | | ||
| `destination-channel`| Channel to which the charm will be released. It must be in the format of `track/risk`. | ✔️ | | ||
| `origin-channel` | Origin Channel from where the charm that needs to be promoted will be pulled. | ✔️ | | ||
| `charm-path` | Path to the charm where `metadata.yaml` is located. Defaults to the current working directory. | | | ||
| `charmcraft-channel` | Snap channel to use when installing charmcraft. Defaults to `latest/edge`. | | | ||
|
||
### Outputs | ||
|
||
None | ||
|
||
### Limitations | ||
- The origin and destination channels must be in the format of `track/risk` for parsing the charmcraft status output. | ||
- Only works for charm. It does not support releasing bundles. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Charmhub Promotion | ||
description: Promote a charm from a channel to another. | ||
author: Luca Bello | ||
inputs: | ||
destination-channel: | ||
required: true | ||
description: | | ||
Channel to which the charm will be released | ||
origin-channel: | ||
required: true | ||
description: | | ||
Origin Channel from where the charm that needs to be promoted will be | ||
pulled. | ||
charm-path: | ||
required: false | ||
default: '.' | ||
description: | | ||
Path to charm directory | ||
charmcraft-channel: | ||
required: false | ||
default: 'latest/edge' | ||
description: | | ||
Snap channel to use when installing charmcraft | ||
credentials: | ||
required: true | ||
description: | | ||
Credentials exported from `charmcraft login --export`. See | ||
https://juju.is/docs/sdk/remote-env-auth for more info | ||
runs: | ||
using: node20 | ||
main: ../dist/release-charm/index.js | ||
branding: | ||
icon: upload-cloud | ||
color: orange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './promote-charm'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import * as core from '@actions/core'; | ||
|
||
import { Snap, Charmcraft, Artifact } from '../../services'; | ||
import { Base } from '../../services/charmcraft/types'; | ||
import { RevisionResourceInfo } from '../../types'; | ||
|
||
export class PromoteCharmAction { | ||
private artifacts: Artifact; | ||
private snap: Snap; | ||
private charmcraft: Charmcraft; | ||
|
||
private destinationChannel: string; | ||
private originChannel: string; | ||
|
||
private charmcraftChannel: string; | ||
private charmPath: string; | ||
|
||
constructor() { | ||
this.destinationChannel = core.getInput('destination-channel'); | ||
this.originChannel = core.getInput('origin-channel'); | ||
this.charmcraftChannel = core.getInput('charmcraft-channel'); | ||
this.charmPath = core.getInput('charm-path'); | ||
|
||
this.artifacts = new Artifact(); | ||
this.snap = new Snap(); | ||
this.charmcraft = new Charmcraft(); | ||
} | ||
|
||
async getRevisions( | ||
name: string, | ||
track: string, | ||
channel: string, | ||
bases: Base[], | ||
): Promise<RevisionResourceInfo[]> { | ||
return Promise.all( | ||
bases.map(async (base: Base) => | ||
this.charmcraft.getRevisionInfoFromChannelJson( | ||
name, | ||
track, | ||
channel, | ||
base, | ||
), | ||
), | ||
); | ||
} | ||
|
||
async run() { | ||
try { | ||
await this.snap.install('charmcraft', this.charmcraftChannel); | ||
process.chdir(this.charmPath!); | ||
const { name: charmName } = this.charmcraft.metadata(); | ||
|
||
const [originTrack, originChannel] = this.originChannel.split('/'); | ||
|
||
const basesArray = await this.charmcraft.getBases(charmName, originTrack); | ||
const revisions = await this.getRevisions( | ||
charmName, | ||
originTrack, | ||
originChannel, | ||
basesArray, | ||
); | ||
await Promise.all( | ||
revisions.map(async ({ charmRev, resources }) => | ||
this.charmcraft.release( | ||
charmName, | ||
charmRev, | ||
this.destinationChannel, | ||
resources, | ||
), | ||
), | ||
); | ||
} catch (error: any) { | ||
core.setFailed(error.message); | ||
core.error(error.stack); | ||
} | ||
|
||
const result = await this.artifacts.uploadLogs(); | ||
core.info(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { PromoteCharmAction } from '../actions/promote-charm/promote-charm'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
(async () => { | ||
await new PromoteCharmAction().run(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters