Skip to content

Commit

Permalink
feat: pass release info to @semantic-release/github
Browse files Browse the repository at this point in the history
The `AMO_BASE_URL` environment variable and the `baseURL` property
now point to the root of AMO instaed of the base of API V5.

This change does not affect almost all use cases, so the major version
is not incremented.
  • Loading branch information
iorate committed Jan 10, 2023
1 parent 3a4d7a8 commit 8de5682
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ This plugin makes it possible to submit source code by using

## Environment variables

| Variable | Description |
| ---------------- | -------------------------------------------------------------------------- |
| `AMO_API_KEY` | **REQUIRED** The API key to publish the add-on to AMO. |
| `AMO_API_SECRET` | **REQUIRED** The API secret to publish the add-on to AMO. |
| `AMO_BASE_URL` | The API base URL. Defaults to `https://addons.mozilla.org/api/v5/addons/`. |
| Variable | Description |
| ---------------- | --------------------------------------------------------------- |
| `AMO_API_KEY` | **REQUIRED** The API key to publish the add-on to AMO. |
| `AMO_API_SECRET` | **REQUIRED** The API secret to publish the add-on to AMO. |
| `AMO_BASE_URL` | The base URL of AMO. Defaults to `https://addons.mozilla.org/`. |

## Options

Expand All @@ -68,7 +68,7 @@ import { updateAddon } from 'semantic-release-amo/update-addon';
await updateAddon({
apiKey: '...',
apiSecret: '...',
baseURL: 'https://addons.mozilla.org/api/v5/addons/', // optional, defaults to 'https://addons.mozilla.org/api/v5/addons/'
baseURL: 'https://addons.mozilla.org/', // optional, defaults to 'https://addons.mozilla.org/'
addonId: '...',
addonZipPath: await generateAddonZip(),
channel: 'listed', // optional, defaults to 'listed'
Expand Down
15 changes: 10 additions & 5 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UpdateAddonError, updateAddon } from './update-addon';
export async function publish(
pluginConfig: Readonly<PluginConfig>,
context: Readonly<FullContext>,
): Promise<void> {
): Promise<{ name: string; url: string }> {
const {
addonId,
addonZipPath: addonZipPathTemplate,
Expand All @@ -18,12 +18,12 @@ export async function publish(
const addonZipPath = applyContext(addonZipPathTemplate, context);
const sourceZipPath = applyContext(sourceZipPathTemplate, context);
const { env, logger, nextRelease } = context;
const baseURL = env.AMO_BASE_URL ?? 'https://addons.mozilla.org/';

if (approvalNotes === '') {
logger.warn('Approval notes are empty. Skipping submission of approval notes.');
}
const releaseNotes = nextRelease.notes;
if (submitReleaseNotes && !releaseNotes) {
if (submitReleaseNotes && !nextRelease.notes) {
logger.warn('Release notes are empty. Skipping submission of release notes.');
}

Expand All @@ -33,13 +33,13 @@ export async function publish(
apiKey: env.AMO_API_KEY!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
apiSecret: env.AMO_API_SECRET!,
baseURL: env.AMO_BASE_URL ?? 'https://addons.mozilla.org/api/v5/addons/',
baseURL,
addonId,
addonZipPath,
channel,
approvalNotes: approvalNotes || null,
compatibility,
releaseNotes: (submitReleaseNotes && releaseNotes) || null,
releaseNotes: (submitReleaseNotes && nextRelease.notes) || null,
sourceZipPath: submitSource ? sourceZipPath : null,
logger,
});
Expand All @@ -50,4 +50,9 @@ export async function publish(
throw error;
}
}

return {
name: 'Firefox Add-ons',
url: new URL(`/en-US/firefox/addon/${addonId}/`, baseURL).toString(),
};
}
18 changes: 6 additions & 12 deletions src/update-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type UpdateAddonParams = {
export async function updateAddon({
apiKey,
apiSecret,
baseURL = 'https://addons.mozilla.org/api/v5/addons/',
baseURL = 'https://addons.mozilla.org/',
addonId,
addonZipPath,
channel = 'listed',
Expand Down Expand Up @@ -98,7 +98,7 @@ async function apiFetch<T>(
): Promise<T> {
try {
const response = await axios({
url: new URL(path, baseURL).toString(),
url: new URL(`/api/v5/addons/${path}`, baseURL).toString(),
method,
headers: {
Authorization: `JWT ${jwtSign(apiKey, apiSecret)}`,
Expand Down Expand Up @@ -147,32 +147,26 @@ type Version = S.Infer<typeof versionStruct>;

function createVersion(
apiParams: Readonly<APIParams>,
addonGuid: string,
addonId: string,
body: Readonly<{
upload: string;
approval_notes?: string;
compatibility?: readonly Application[];
release_notes?: Readonly<Record<string, string>>;
}>,
): Promise<Version> {
return apiFetch(apiParams, 'POST', `addon/${addonGuid}/versions/`, body, versionStruct);
return apiFetch(apiParams, 'POST', `addon/${addonId}/versions/`, body, versionStruct);
}

function patchVersion(
apiParams: Readonly<APIParams>,
addonGuid: string,
addonId: string,
id: number,
{ source }: Readonly<{ source: fs.ReadStream }>,
): Promise<Version> {
const formData = new FormData();
formData.append('source', source);
return apiFetch(
apiParams,
'PATCH',
`addon/${addonGuid}/versions/${id}/`,
formData,
versionStruct,
);
return apiFetch(apiParams, 'PATCH', `addon/${addonId}/versions/${id}/`, formData, versionStruct);
}

function waitForValidation(apiParams: Readonly<APIParams>, uuid: string): Promise<void> {
Expand Down

0 comments on commit 8de5682

Please sign in to comment.