-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…3639) * chore: update PR release to GitHub packages * chore: release PR * chore: correct terminology * chore: maybe works * chore: attempt different token * pls pickup .npmrc * chore: set registry for changeset * fix: envs * remove env * chore: finalize GitHub package publishing * disable whoami * chore: need to alter the changeset config * pls * chore: need to update all the changesets * chore: added better comment * chore: removed (potentially unneeded envs) * chore: re-added envs * chore: fix ci name * chore: removed potentially unneeded config * fix: names of organisation * chore: removed failing command * chore: remove redundant action * chore: changing the script name * chore: readd registry-url * fix: script name * pls deploy * chore: finalise PR * chore: changeset * chore: rollback unneeded changes * disable release --------- Co-authored-by: Nedim Salkić <nedim.salkic@fuel.sh>
- Loading branch information
1 parent
6668336
commit 95255c8
Showing
8 changed files
with
180 additions
and
50 deletions.
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,4 @@ | ||
--- | ||
--- | ||
|
||
chore: migrate `pr` + `next` package publishing to GitHub Packages |
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 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,71 @@ | ||
name: Release to @pr-<number> tag on GitHub Packages | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
release-pr: | ||
name: "Release PR to GitHub Packages" | ||
runs-on: ubuntu-latest | ||
# comment out if:false to enable release PR to GitHub Packages | ||
if: false | ||
permissions: write-all | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
|
||
- name: CI Setup | ||
uses: ./.github/actions/ci-setup | ||
|
||
- name: Create .npmrc | ||
run: | | ||
cat << EOF > "$HOME/.npmrc" | ||
//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN | ||
@FuelLabs:registry=https://npm.pkg.github.com | ||
EOF | ||
env: | ||
HOME: ${{ github.workspace }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build | ||
run: pnpm build | ||
|
||
- name: Release to @pr-${{ github.event.pull_REQUEST.NUMBER }} tag on GitHub Packages | ||
id: release | ||
shell: bash | ||
run: | | ||
pnpm changeset:next | ||
pnpm changeset version --snapshot pr-${{ github.event.pull_REQUEST.NUMBER }} | ||
changetsets=$(pnpm changeset publish --tag pr-${{ github.event.pull_REQUEST.NUMBER }}) | ||
published_version=$(echo "$changetsets" | grep -oP '@\K([0-9]+\.){2}[0-9]+-pr-${{ github.event.pull_REQUEST.NUMBER }}-\d+' | head -1) | ||
echo "published_version=$published_version" >> $GITHUB_OUTPUT | ||
env: | ||
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
HOME: ${{ github.workspace }} | ||
npm_config_registry: "https://npm.pkg.github.com" | ||
|
||
- uses: mshick/add-pr-comment@v2 | ||
with: | ||
message: | | ||
This PR is published in GitHub Packages with version **${{ steps.release.outputs.published_version }}** | ||
Install using the following command: | ||
```bash | ||
pnpm add @fuellabs/fuels@${{ steps.release.outputs.published_version }} | ||
``` | ||
Or update your package.json: | ||
```json | ||
"dependencies": { | ||
"@fuellabs/fuels": "${{ steps.release.outputs.published_version }}" | ||
} | ||
``` | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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
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,84 @@ | ||
import { execSync } from "child_process"; | ||
import { readFileSync, writeFileSync } from "fs"; | ||
import { globSync } from "glob"; | ||
|
||
const CHANGESET_CONFIG_PATH = ".changeset/config.json"; | ||
const GITHUB_ORGANIZATION_SCOPE = "@FuelLabs"; | ||
|
||
const formatPackageName = (name: string) => | ||
`${GITHUB_ORGANIZATION_SCOPE}/${name.replace("@fuel-ts/", "")}`; | ||
|
||
const formatPackageJsonContents = (contents: { name: string }) => ({ | ||
...contents, | ||
// We need to add the GitHub organization name to the scope to publish to GitHub | ||
// We also need to strip off and prefixes (e.g. '@fuel-ts/' -> '') | ||
name: formatPackageName(contents.name), | ||
// We also need a repository field to publish to GitHub | ||
repository: "https://github.com/FuelLabs/fuels-ts", | ||
}); | ||
|
||
/** | ||
* Gather all the package.json files to be published | ||
*/ | ||
const packages = globSync("**/package.json") | ||
// Read in the package.json file | ||
.map((fileName) => { | ||
const packageJson = JSON.parse(readFileSync(fileName, "utf-8")); | ||
return { | ||
path: fileName, | ||
contents: packageJson, | ||
}; | ||
}) | ||
// Filter out private packages | ||
.filter((pkg) => !pkg.contents.private); | ||
|
||
// Format the package contents to be used to publish to GitHub | ||
packages | ||
.map((pkg) => ({ | ||
path: pkg.path, | ||
contents: formatPackageJsonContents(pkg.contents), | ||
})) | ||
.forEach((pkg) => { | ||
// Write the formatted package.json files | ||
writeFileSync(pkg.path, JSON.stringify(pkg.contents, null, 2)); | ||
// Add the formatted package.json files to the git index | ||
execSync(`git add ${pkg.path}`); | ||
}); | ||
|
||
/** | ||
* Update the changeset config to include the FuelLabs organization scope | ||
*/ | ||
const changesetConfigContents = JSON.parse( | ||
readFileSync(CHANGESET_CONFIG_PATH, "utf-8"), | ||
); | ||
const changesetConfig = { | ||
...changesetConfigContents, | ||
fixed: [[`${GITHUB_ORGANIZATION_SCOPE}/*`]], | ||
}; | ||
writeFileSync(CHANGESET_CONFIG_PATH, JSON.stringify(changesetConfig, null, 2)); | ||
execSync(`git add ${CHANGESET_CONFIG_PATH}`); | ||
|
||
/** | ||
* Update all pre-existing changeset package scopes | ||
*/ | ||
const packageNames = packages.map((pkg) => pkg.contents.name).join("|"); | ||
const regex = new RegExp(packageNames, "g"); | ||
globSync(".changeset/*.md") | ||
.map((fileName) => { | ||
const contents = readFileSync(fileName, "utf-8"); | ||
return { | ||
path: fileName, | ||
contents, | ||
}; | ||
}) | ||
.forEach((pkg) => { | ||
writeFileSync(pkg.path, pkg.contents.replace(regex, formatPackageName)); | ||
execSync(`git add ${pkg.path}`); | ||
}); | ||
|
||
/** | ||
* Add a changeset for the next `fuels` version | ||
*/ | ||
const output = `---\n"${GITHUB_ORGANIZATION_SCOPE}/fuels": patch\n---\n\nincremental\n`; | ||
writeFileSync(".changeset/fuel-labs-ci.md", output); | ||
execSync(`git add .changeset/fuel-labs-ci.md`); |
This file was deleted.
Oops, something went wrong.