|
1 | 1 | import axios from "axios";
|
2 |
| -import { BaseContext } from "semantic-release"; |
| 2 | +import { PublishContext } from "semantic-release"; |
3 | 3 |
|
4 | 4 | import { PluginConfig } from "./types/pluginConfig";
|
5 |
| -import { runExecCommand } from "./utils/exec"; |
6 | 5 |
|
7 |
| -export const HACKAGE_PACKAGES_URL = "https://hackage.haskell.org/package"; |
8 |
| -export const CANDIDATES_PATH = "candidates/"; |
| 6 | +import fs from "fs"; |
| 7 | + |
| 8 | +export const HACKAGE_CANDIDATES_URL = "https://hackage.haskell.org/packages/candidates"; |
9 | 9 |
|
10 | 10 | export const postReleaseCandidate = async (
|
11 | 11 | sdistPath: string,
|
12 |
| - packageName: string, |
13 | 12 | hackageToken?: string,
|
14 | 13 | ): Promise<number | undefined> => {
|
15 |
| - const url = `${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES_PATH}`; |
16 | 14 | try {
|
17 | 15 | const headers = {
|
18 | 16 | Accept: "text/plain",
|
19 | 17 | Authorization: `X-ApiKey ${hackageToken}`,
|
| 18 | + "Content-Type": "multipart/form-data", |
20 | 19 | };
|
21 | 20 |
|
22 |
| - const formData = new FormData(); |
23 |
| - formData.append("package", sdistPath); |
24 |
| - |
25 |
| - const req = await axios.post(url, formData, { headers }); |
| 21 | + const req = await axios.post(HACKAGE_CANDIDATES_URL, { package: fs.createReadStream(sdistPath) }, { headers }); |
26 | 22 |
|
27 | 23 | return req.status;
|
28 | 24 | } catch (e: unknown) {
|
29 |
| - throw e instanceof Error ? new Error(`You do not have access to POST a file to ${url}, ${e.message}`) : e; |
| 25 | + throw e instanceof Error |
| 26 | + ? new Error(`You do not have access to POST a file to ${HACKAGE_CANDIDATES_URL} , ${e.message}`) |
| 27 | + : e; |
30 | 28 | }
|
31 | 29 | };
|
32 | 30 |
|
33 |
| -export const publish = async ({ packageName }: PluginConfig, { logger }: BaseContext): Promise<void> => { |
34 |
| - logger.log("Getting sdist path"); |
35 |
| - const { error, output } = await runExecCommand(`ls dist-newstyle/sdist/${packageName}-*.tar.gz`); |
36 |
| - |
37 |
| - if (error) { |
38 |
| - logger.error(error); |
39 |
| - throw new Error(error); |
40 |
| - } |
| 31 | +export const publish = async ( |
| 32 | + { packageName, versionPrefix }: PluginConfig, |
| 33 | + { logger, nextRelease, cwd }: PublishContext, |
| 34 | +): Promise<void> => { |
| 35 | + const realCwd = cwd ?? process.cwd(); |
| 36 | + logger.log("Current working directory: ", realCwd); |
| 37 | + const { version } = nextRelease; |
| 38 | + logger.log("Getting sdist path with version: ", version); |
| 39 | + const filename = `${packageName}-${versionPrefix}${version}.tar.gz`; |
| 40 | + const sdistPath = `${realCwd}/dist-newstyle/sdist/${filename}`; |
| 41 | + logger.log("Uploading sdist: ", sdistPath); |
41 | 42 |
|
42 | 43 | logger.log("Post release candidate in hackage");
|
43 |
| - const status = await postReleaseCandidate(output.trim(), packageName, process.env.HACKAGE_TOKEN); |
| 44 | + const status = await postReleaseCandidate(sdistPath, process.env.HACKAGE_TOKEN); |
44 | 45 |
|
45 | 46 | if (status !== 200) {
|
46 | 47 | throw new Error(`Cannot post release candidate now, status: ${status}`);
|
|
0 commit comments