Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store deployments in json file, and generate md and txt file from that #6044

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions scripts/build-deployments-readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable no-console */
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert');

const itemCountMd = 100;
const txtFileName = 'deployments.txt';

async function go() {
// eslint-disable-next-line no-undef
const [, , deploymentsFile, outputDir] = process.argv;

assert(deploymentsFile, 'Missing deploymentsFile');
assert(outputDir, 'Missing outputDir');

const { stable, latest, individual } = JSON.parse(
await fs.promises.readFile(deploymentsFile, { encoding: 'utf-8' }),
);

const mdContent = `# Deployments

- **Stable:** [${stable}](${stable})
- **Latest:** [${latest}](${latest})

Below you can find the URL's to deployments for individual commits:

${Array.from(individual)
.reverse()
.slice(0, itemCountMd)
.map(
({ commit, version, url }) =>
`- [\`${commit.slice(
0,
8,
)} (${version})\`](https://github.com/video-dev/hls.js/commit/${commit}): [${url}](${url})`,
)
.join('\n')}

_Note for older deployments please check [${txtFileName}](./${txtFileName})._
`;

await fs.promises.writeFile(path.resolve(outputDir, 'README.md'), mdContent, {
encoding: 'utf-8',
});

const txtContent = `Deployments
===========

- Stable: ${stable}
- Latest: ${latest}

Below you can find the URL's to deployments for individual commits:

${Array.from(individual)
.reverse()
.map(
({ commit, version, url }) =>
`- ${commit.slice(0, 8)} (${version}): ${url}`,
)
.join('\n')}
`;

await fs.promises.writeFile(
path.resolve(outputDir, txtFileName),
txtContent,
{
encoding: 'utf-8',
},
);
}

go().catch((e) => {
console.error(e);
// eslint-disable-next-line no-undef
process.exit(1);
});
25 changes: 23 additions & 2 deletions scripts/deploy-cloudflare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ currentCommit=$(git rev-parse HEAD)

root="./cloudflare-pages"
version="$(jq -r -e '.version' "./package.json")"
idShort="$(echo "$currentCommit" | cut -c 1-8) ($version)"

deploy () {
projectName=$1
Expand All @@ -37,8 +36,30 @@ deploymentUrl=`curl -X GET --fail "https://api.cloudflare.com/client/v4/accounts
echo "Updating deployments branch."
git clone --depth 1 "https://${GITHUB_TOKEN}@github.com/video-dev/hls.js.git" -b deployments "$root/deployments"
cd "$root/deployments"
echo "- [\`$idShort\`](https://github.com/video-dev/hls.js/commit/$currentCommit): [$deploymentUrl/]($deploymentUrl/)" >> "README.md"

jq '.stable = "https://hlsjs.video-dev.org/"' deployments.json > deployments.json.tmp
mv deployments.json.tmp deployments.json

jq '.latest = "https://hlsjs-dev.video-dev.org/"' deployments.json > deployments.json.tmp
mv deployments.json.tmp deployments.json

jq \
--arg version "$version" \
--arg commit "$currentCommit" \
--arg url "$deploymentUrl" \
'.individual += [{
"version": $version,
"commit": $commit,
"url": $url,
}]' deployments.json > deployments.json.tmp
mv deployments.json.tmp deployments.json

node scripts/build-deployments-readme.js './deployments.json' '.'

git add "deployments.json"
git add "deployments.txt"
git add "README.md"

git -c user.name="hlsjs-ci" -c user.email="[email protected]" commit -m "update for $id"
git push "https://${GITHUB_TOKEN}@github.com/video-dev/hls.js.git"
cd ..
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"tests/**/.eslintrc.js",
"rollup.config.js",
"build-config.js",
"lint-staged.config.js"
"lint-staged.config.js",
"scripts/**/*"
]
}
Loading