mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Chore: Resolves #8697: Rename releases such that MacOS x86_64 releases are selected by old versions of Joplin (#8731)
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
parent
ea4d54aea6
commit
406365f0e0
@ -368,6 +368,7 @@ packages/app-desktop/services/sortOrder/notesSortOrderUtils.test.js
|
||||
packages/app-desktop/services/sortOrder/notesSortOrderUtils.js
|
||||
packages/app-desktop/services/spellChecker/SpellCheckerServiceDriverNative.js
|
||||
packages/app-desktop/tools/notarizeMacApp.js
|
||||
packages/app-desktop/tools/renameReleaseAssets.js
|
||||
packages/app-desktop/utils/checkForUpdatesUtils.test.js
|
||||
packages/app-desktop/utils/checkForUpdatesUtils.js
|
||||
packages/app-desktop/utils/checkForUpdatesUtilsTestData.js
|
||||
|
5
.github/workflows/build-macos-m1.yml
vendored
5
.github/workflows/build-macos-m1.yml
vendored
@ -41,7 +41,8 @@ jobs:
|
||||
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
|
||||
CSC_KEY_PASSWORD: ${{ secrets.APPLE_CSC_KEY_PASSWORD }}
|
||||
CSC_LINK: ${{ secrets.APPLE_CSC_LINK }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GH_REPO: ${{ github.repository }}
|
||||
IS_CONTINUOUS_INTEGRATION: 1
|
||||
BUILD_SEQUENCIAL: 1
|
||||
run: |
|
||||
@ -56,6 +57,8 @@ jobs:
|
||||
if [[ $GIT_TAG_NAME = v* ]]; then
|
||||
echo "Building and publishing desktop application..."
|
||||
PYTHON_PATH=$(which python) USE_HARD_LINKS=false yarn run dist --mac --arm64
|
||||
|
||||
yarn renameReleaseAssets --repo="$GH_REPO" --tag="$GIT_TAG_NAME" --token="$GITHUB_TOKEN"
|
||||
else
|
||||
echo "Building but *not* publishing desktop application..."
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -354,6 +354,7 @@ packages/app-desktop/services/sortOrder/notesSortOrderUtils.test.js
|
||||
packages/app-desktop/services/sortOrder/notesSortOrderUtils.js
|
||||
packages/app-desktop/services/spellChecker/SpellCheckerServiceDriverNative.js
|
||||
packages/app-desktop/tools/notarizeMacApp.js
|
||||
packages/app-desktop/tools/renameReleaseAssets.js
|
||||
packages/app-desktop/utils/checkForUpdatesUtils.test.js
|
||||
packages/app-desktop/utils/checkForUpdatesUtils.js
|
||||
packages/app-desktop/utils/checkForUpdatesUtilsTestData.js
|
||||
|
@ -14,7 +14,8 @@
|
||||
"watch": "tsc --watch --preserveWatchOutput --project tsconfig.json",
|
||||
"start": "gulp build && electron . --env dev --log-level debug --open-dev-tools",
|
||||
"test": "jest",
|
||||
"test-ci": "yarn test"
|
||||
"test-ci": "yarn test",
|
||||
"renameReleaseAssets": "node tools/renameReleaseAssets.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
109
packages/app-desktop/tools/renameReleaseAssets.ts
Normal file
109
packages/app-desktop/tools/renameReleaseAssets.ts
Normal file
@ -0,0 +1,109 @@
|
||||
import { parseArgs } from 'util';
|
||||
|
||||
interface Context {
|
||||
repo: string; // {owner}/{repo}
|
||||
githubToken: string;
|
||||
}
|
||||
|
||||
const apiBaseUrl = 'https://api.github.com/repos/';
|
||||
const defaultApiHeaders = (context: Context) => ({
|
||||
'Authorization': `token ${context.githubToken}`,
|
||||
'X-GitHub-Api-Version': '2022-11-28',
|
||||
'Accept': 'application/vnd.github+json',
|
||||
});
|
||||
|
||||
const getTargetRelease = async (context: Context, targetTag: string) => {
|
||||
console.log('Fetching releases...');
|
||||
|
||||
// Note: We need to fetch all releases, not just /releases/tag/tag-name-here.
|
||||
// The latter doesn't include draft releases.
|
||||
|
||||
const result = await fetch(`${apiBaseUrl}${context.repo}/releases`, {
|
||||
method: 'GET',
|
||||
headers: defaultApiHeaders(context),
|
||||
});
|
||||
|
||||
const releases = await result.json();
|
||||
if (!result.ok) {
|
||||
throw new Error(`Error fetching release: ${JSON.stringify(releases)}`);
|
||||
}
|
||||
|
||||
for (const release of releases) {
|
||||
if (release.tag_name === targetTag) {
|
||||
return release;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`No release with tag ${targetTag} found!`);
|
||||
};
|
||||
|
||||
const updateReleaseAsset = async (context: Context, assetUrl: string, newName: string) => {
|
||||
console.log('Updating asset with URL', assetUrl, 'to have name, ', newName);
|
||||
|
||||
// See https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#update-a-release-asset
|
||||
const result = await fetch(assetUrl, {
|
||||
method: 'PATCH',
|
||||
headers: defaultApiHeaders(context),
|
||||
body: JSON.stringify({
|
||||
name: newName,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
throw new Error(`Unable to update release asset: ${await result.text()}`);
|
||||
}
|
||||
};
|
||||
|
||||
// Renames release assets in Joplin Desktop releases
|
||||
const renameReleaseAssets = async () => {
|
||||
const args = parseArgs({
|
||||
options: {
|
||||
tag: { type: 'string' },
|
||||
token: { type: 'string' },
|
||||
repo: { type: 'string' },
|
||||
},
|
||||
});
|
||||
|
||||
if (!args.values.tag || !args.values.token || !args.values.repo) {
|
||||
throw new Error([
|
||||
'Required arguments: --tag, --token, --repo',
|
||||
' --tag should be a git tag with an associated release (e.g. v12.12.12)',
|
||||
' --token should be a GitHub API token',
|
||||
' --repo should be a string in the form user/reponame (e.g. laurent22/joplin)',
|
||||
].join('\n'));
|
||||
}
|
||||
|
||||
|
||||
const context: Context = {
|
||||
repo: args.values.repo,
|
||||
githubToken: args.values.token,
|
||||
};
|
||||
|
||||
console.log('Renaming release assets for tag', args.values.tag, context.repo);
|
||||
|
||||
const release = await getTargetRelease(context, args.values.tag);
|
||||
|
||||
if (!release.assets) {
|
||||
console.log(release);
|
||||
throw new Error(`Release ${release.name} missing assets!`);
|
||||
}
|
||||
|
||||
// Patterns used to rename releases
|
||||
const renamePatterns = [
|
||||
[/-arm64\.dmg$/, '-arm64.DMG'],
|
||||
];
|
||||
|
||||
for (const asset of release.assets) {
|
||||
for (const [pattern, replacement] of renamePatterns) {
|
||||
if (asset.name.match(pattern)) {
|
||||
const newName = asset.name.replace(pattern, replacement);
|
||||
await updateReleaseAsset(context, asset.url, newName);
|
||||
|
||||
// Only rename a release once.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void renameReleaseAssets();
|
Loading…
Reference in New Issue
Block a user