-
Notifications
You must be signed in to change notification settings - Fork 10
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
refactor(CI/CD): replace shell script by JavaScript #3454
Open
mfranzke
wants to merge
14
commits into
main
Choose a base branch
from
refactor-cicd-replace-shell-by-javascript
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+216
−101
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c1ee3cb
refactor(CI/CD): replace shell by JavaScript
mfranzke d9d2fa4
refactor: we obviously need to provide and export that function
mfranzke a2b65c0
Merge branch 'main' into refactor-cicd-replace-shell-by-javascript
mfranzke 83298f5
refactor: removed that file again
mfranzke a95e172
refactor: migrated another script
mfranzke cae6f80
refactor: removed incorrect import
mfranzke 7f6d2b4
chore: removed leftover
mfranzke 6d175bf
refactor: this was way too complicated
mfranzke 17dd84d
refactor: migrated another script
mfranzke 54a0475
refactor: added dependency
mfranzke 95d0bbd
Revert "refactor: added dependency"
mfranzke 4bdf083
Reapply "refactor: added dependency"
mfranzke cdd8dc3
refactor: corrected this implementation
mfranzke dfdc409
chore: another try
mfranzke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use |
||
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 = `<meta http-equiv="refresh" content="0; URL=https://${OWNER_NAME}.github.io/${REPO_NAME}/version/latest" />`; | ||
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; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have this dependency in our
package.json
?