diff --git a/.github/scripts/build-gh-page.js b/.github/scripts/build-gh-page.js new file mode 100644 index 00000000000..98c7878daae --- /dev/null +++ b/.github/scripts/build-gh-page.js @@ -0,0 +1,65 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import tar from 'tar'; + +const buildGitHubPage = () => { + const NAME = process.env.NAME; + const OWNER_NAME = process.env.OWNER_NAME; + const REPO_NAME = process.env.REPO_NAME; + const RELEASE = process.env.RELEASE === 'true'; + const PRE_RELEASE = process.env.PRE_RELEASE === 'true'; + + if (!NAME) { + console.error('Error: Missing NAME variable'); + process.exit(1); + } + + console.log('➕ Create public dir'); + if (!fs.existsSync('public')) { + fs.mkdirSync('public'); + } + + console.log('📥 Get gh-pages tar'); + fetch(`https://github.com/${OWNER_NAME}/${REPO_NAME}/tarball/gh-pages`) + .then((res) => { + if (!res.ok) { + throw new Error(`Failed to fetch tarball: ${res.statusText}`); + } + return res.arrayBuffer(); + }) + .then((buffer) => { + fs.writeFileSync('gh-pages.tar.gz', Buffer.from(buffer)); + console.log('📦 Unpack Tar'); + return tar.x({ + file: 'gh-pages.tar.gz', + C: 'public', + strip: 1 + }); + }) + .then(() => { + if (RELEASE) { + console.log('🔃 Create redirect'); + const redirectContent = ``; + fs.writeFileSync( + path.join('public', 'index.html'), + redirectContent + ); + } + + console.log('👣 Move out dir'); + if (PRE_RELEASE || RELEASE) { + const versionDir = path.join('public', 'version'); + if (!fs.existsSync(versionDir)) { + console.log(' Make dir ./public/version'); + fs.mkdirSync(versionDir); + } + const nameDir = path.join(versionDir, NAME); + if (fs.existsSync(nameDir)) { + console.log(` Remove dir ./public/version/${NAME}`); + fs.rmdirSync(nameDir, { recursive: true }); + } + } + }) + .catch((err) => console.error(err)); +}; +export default buildGitHubPage; diff --git a/.github/scripts/build-gh-page.sh b/.github/scripts/build-gh-page.sh deleted file mode 100755 index 0eb12b5f75c..00000000000 --- a/.github/scripts/build-gh-page.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash - -if [[ $NAME == "true" ]]; then - echo "Erro: Missing NAME variable" - exit 1 -fi - -echo "➕ Create public dir" -mkdir public - -echo "📥 Get gh-pages tar" -curl -L https://github.com/"$OWNER_NAME"/"$REPO_NAME"/tarball/gh-pages --output gh-pages - -echo "📦 Unpack Tar" -tar -zxf gh-pages -C public --strip-components 1 - -if [[ $RELEASE == "true" ]]; then - echo "🔃 Create redirect" - echo "" > public/index.html -fi - -echo "👣 Move out dir" -if [[ $PRE_RELEASE == "true" || $RELEASE == "true" ]]; then - if [[ ! -d ./public/version ]]; then - echo " Make dir ./public/version" - mkdir ./public/version - fi - if [[ -d ./public/version/"$NAME" ]]; then - echo " Remove dir ./public/version/$NAME" - rm -rf ./public/version/"$NAME" - fi - if [[ $RELEASE == "true" ]]; then - if [[ -d ./public/version/latest ]]; then - echo " Remove dir ./public/version/latest" - rm -rf ./public/version/latest - fi - mkdir ./public/version/latest - cp -RT ./out ./public/version/latest - echo " Copied dir out to ./public/version/latest" - fi - mv ./out ./public/version/"$NAME" - echo " Moved dir out to ./public/version/$NAME" -else - if [[ ! -d ./public/review ]]; then - echo " Make dir ./public/review" - mkdir ./public/review - fi - if [[ -d ./public/review/"$NAME" ]]; then - echo " Remove dir ./public/review/$NAME" - rm -rf ./public/review/"$NAME" - fi - mv ./out ./public/review/"$NAME" - echo " Moved dir out to ./public/review/$NAME" -fi diff --git a/.github/scripts/get-release.js b/.github/scripts/get-release.js new file mode 100644 index 00000000000..bf2730ae0c3 --- /dev/null +++ b/.github/scripts/get-release.js @@ -0,0 +1,20 @@ +const GITHUB_REF = process.env.GITHUB_REF; +const GITHUB_ACTOR = process.env.GITHUB_ACTOR; +const GITHUB_COMMITISH = process.env.GITHUB_COMMITISH; +const GITHUB_PRE_RELEASE = process.env.GITHUB_PRE_RELEASE === 'true'; + +if (GITHUB_REF && GITHUB_REF.startsWith('refs/tags/v')) { + if (GITHUB_ACTOR !== 'dependabot[bot]') { + if (GITHUB_COMMITISH === 'main' && !GITHUB_PRE_RELEASE) { + console.log('RELEASE'); + } else { + console.log('PRE_RELEASE'); + } + } else { + console.error('Dependabot has no permission to publish!'); + process.exit(1); + } +} else { + console.error("Your tag has to start with 'v'"); + process.exit(1); +} diff --git a/.github/scripts/get-release.sh b/.github/scripts/get-release.sh deleted file mode 100644 index 0b2b500d9b8..00000000000 --- a/.github/scripts/get-release.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -if [[ $GITHUB_REF == refs/tags/v* ]]; then - if [[ $GITHUB_ACTOR != 'dependabot[bot]' ]]; then - if [[ $GITHUB_COMMITISH == 'main' && $GITHUB_PRE_RELEASE == false ]]; then - echo "RELEASE" - else - echo "PRE_RELEASE" - fi - else - echo "Dependabot has no permission to publish!" - exit 1 - fi -else - echo "Your tag has to start with 'v'" - exit 1 -fi diff --git a/.github/scripts/package-version.js b/.github/scripts/package-version.js new file mode 100644 index 00000000000..4341a866fe8 --- /dev/null +++ b/.github/scripts/package-version.js @@ -0,0 +1,32 @@ +import findVersions from 'find-versions'; + +const TAG = process.env.TAG; +const RELEASE = process.env.RELEASE === 'true'; +const PRE_RELEASE = process.env.PRE_RELEASE === 'true'; +const GITHUB_SHA = process.env.GITHUB_SHA; + +const SEMVER_VERSION = findVersions(TAG).toString(); + +if (RELEASE) { + if (SEMVER_VERSION.includes('-')) { + console.error( + `Version ${SEMVER_VERSION} contains hyphen, maybe you forgot to check the prerelease checkbox in GitHub release draft. A release should not have a hyphen!` + ); + process.exit(1); + } + console.log(SEMVER_VERSION); +} else if (PRE_RELEASE) { + if (SEMVER_VERSION.includes('-')) { + const GITHUB_SHA_SHORT = GITHUB_SHA.substring(0, 7); + const VALID_SEMVER_VERSION = `${SEMVER_VERSION}-${GITHUB_SHA_SHORT}`; + console.log(VALID_SEMVER_VERSION); + } else { + console.error( + `Version ${SEMVER_VERSION} doesn't contain a hyphen. A prerelease should have a hyphen!` + ); + process.exit(1); + } +} else { + console.error('nothing found in environment for RELEASE or PRE_RELEASE'); + process.exit(1); +} diff --git a/.github/scripts/package-version.sh b/.github/scripts/package-version.sh deleted file mode 100644 index 34327d70f3c..00000000000 --- a/.github/scripts/package-version.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -SEMVER_VERSION=$(npx find-versions-cli "$TAG") -if [[ $RELEASE == "true" ]]; then - if [[ $SEMVER_VERSION == *-* ]]; then - echo "Version $SEMVER_VERSION contains hyphen, maybe you forgot to check the prerelease checkbox in GitHub release draft. A release should not have a hyphen!" - exit 1 - fi - echo "$SEMVER_VERSION" -elif [[ $PRE_RELEASE == "true" ]]; then - if [[ $SEMVER_VERSION == *-* ]]; then - GITHUB_SHA_SHORT=$(echo "$GITHUB_SHA" | cut -c1-7) - VALID_SEMVER_VERSION=$(echo "$SEMVER_VERSION"-"$GITHUB_SHA_SHORT") - echo "$VALID_SEMVER_VERSION" - else - echo "Version $SEMVER_VERSION doesn't contain a hyphen. A prerelease should have a hyphen!" - exit 1 - fi -else - echo "nothing found in environment for REALEASE or PRE_RELEASE" - exit 1 -fi diff --git a/.github/workflows/01-get-publish-version.yml b/.github/workflows/01-get-publish-version.yml index 4a0caf59e4d..e41a61c50a0 100644 --- a/.github/workflows/01-get-publish-version.yml +++ b/.github/workflows/01-get-publish-version.yml @@ -33,8 +33,7 @@ jobs: - name: 💃🕺 Check if release or prerelease id: releaseCheck run: | - chmod +rx ./.github/scripts/get-release.sh - OUTPUT=$(./.github/scripts/get-release.sh) + OUTPUT=$(node .github/scripts/get-release.js) if [[ $OUTPUT == "RELEASE" ]]; then echo "release=true" >> $GITHUB_OUTPUT @@ -60,8 +59,7 @@ jobs: PRE_RELEASE: ${{ steps.releaseCheck.outputs.preRelease }} TAG: ${{ steps.extractTag.outputs.tag }} run: | - chmod +rx ./.github/scripts/package-version.sh - OUTPUT=$(./.github/scripts/package-version.sh) + OUTPUT=$(node .github/scripts/package-version.js) echo "version=$OUTPUT" >> $GITHUB_OUTPUT - name: 🌳 Log Valid Version diff --git a/.github/workflows/03-deploy-gh-pages.yml b/.github/workflows/03-deploy-gh-pages.yml index 303446386d7..f2a4e6651dd 100644 --- a/.github/workflows/03-deploy-gh-pages.yml +++ b/.github/workflows/03-deploy-gh-pages.yml @@ -62,15 +62,17 @@ jobs: script: return context?.payload?.repository?.name - name: 🔨 Build page + uses: actions/github-script@v7 env: RELEASE: ${{ inputs.release }} PRE_RELEASE: ${{ inputs.preRelease }} NAME: ${{ steps.extract.outputs.name }} REPO_NAME: ${{ steps.repo-name.outputs.result }} OWNER_NAME: ${{ github.repository_owner }} - run: | - chmod +rx ./.github/scripts/build-gh-page.sh - ./.github/scripts/build-gh-page.sh + with: + script: | + const { default: buildGitHubPage } = await import('${{ github.workspace }}/.github/scripts/build-gh-page.js'); + return await buildGitHubPage(); - name: 🥅 Deploy to GH-Pages uses: peaceiris/actions-gh-pages@v4 diff --git a/package-lock.json b/package-lock.json index 3efe4c0156f..dd36b76c3e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "cross-env": "^7.0.3", "dotenv": "^16.4.7", "eslint-plugin-prettier": "^5.2.1", + "find-versions": "^6.0.0", "fs-extra": "^11.2.0", "glob": "^11.0.0", "http-server": "14.1.1", @@ -15257,6 +15258,19 @@ "node": ">=16" } }, + "node_modules/convert-hrtime": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/convert-hrtime/-/convert-hrtime-5.0.0.tgz", + "integrity": "sha512-lOETlkIeYSJWcbbcvjRKGxVMXJR+8+OQb/mTPbA4ObPMytYIsUbuOE0Jzy60hjARYszq1id0j8KgVhC+WGZVTg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/convert-source-map": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", @@ -19246,6 +19260,23 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/find-versions": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/find-versions/-/find-versions-6.0.0.tgz", + "integrity": "sha512-2kCCtc+JvcZ86IGAz3Z2Y0A1baIz9fL31pH/0S1IqZr9Iwnjq8izfPtrCyQKO6TLMPELLsQMre7VDqeIKCsHkA==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver-regex": "^4.0.5", + "super-regex": "^1.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/flat": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", @@ -19597,6 +19628,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/function-timeout": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/function-timeout/-/function-timeout-1.0.2.tgz", + "integrity": "sha512-939eZS4gJ3htTHAldmyyuzlrD58P03fHG49v2JfFXbV6OhvZKRC9j2yAtdHw/zrp2zXHuv05zMIy40F0ge7spA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/function.prototype.name": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.6.tgz", @@ -32028,6 +32072,19 @@ "node": ">=10" } }, + "node_modules/semver-regex": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/semver-regex/-/semver-regex-4.0.5.tgz", + "integrity": "sha512-hunMQrEy1T6Jr2uEVjrAIqjwWcQTgOAcIM52C8MY1EZSD3DDNft04XzvYKPqjED65bNVVko0YI38nYeEHCX3yw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/send": { "version": "0.19.0", "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", @@ -33638,6 +33695,23 @@ "node": ">=8" } }, + "node_modules/super-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/super-regex/-/super-regex-1.0.0.tgz", + "integrity": "sha512-CY8u7DtbvucKuquCmOFEKhr9Besln7n9uN8eFbwcoGYWXOMW07u2o8njWaiXt11ylS3qoGF55pILjRmPlbodyg==", + "dev": true, + "license": "MIT", + "dependencies": { + "function-timeout": "^1.0.1", + "time-span": "^5.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/superjson": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/superjson/-/superjson-2.2.2.tgz", @@ -34282,6 +34356,22 @@ "integrity": "sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==", "dev": true }, + "node_modules/time-span": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/time-span/-/time-span-5.1.0.tgz", + "integrity": "sha512-75voc/9G4rDIJleOo4jPvN4/YC4GRZrY8yy1uU4lwrB3XEQbWve8zXoO5No4eFrGcTAMYyoY67p8jRQdtA1HbA==", + "dev": true, + "license": "MIT", + "dependencies": { + "convert-hrtime": "^5.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/tiny-invariant": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.3.tgz", @@ -39891,7 +39981,7 @@ }, "showcases/next-showcase": { "dependencies": { - "next": "*", + "next": "latest", "react": "18.3.1", "react-dom": "18.3.1" }, diff --git a/package.json b/package.json index 74f623d3dea..bfe984144e2 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "cross-env": "^7.0.3", "dotenv": "^16.4.7", "eslint-plugin-prettier": "^5.2.1", + "find-versions": "^6.0.0", "fs-extra": "^11.2.0", "glob": "^11.0.0", "http-server": "14.1.1",