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

chore: migrate pr + next package publishing to GitHub Packages #3639

Merged
merged 32 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4dbb2a2
chore: update PR release to GitHub packages
petertonysmith94 Jan 29, 2025
c786b87
chore: release PR
petertonysmith94 Jan 29, 2025
28d190a
chore: correct terminology
petertonysmith94 Jan 29, 2025
8b93450
chore: maybe works
petertonysmith94 Jan 29, 2025
4dfb41f
chore: attempt different token
petertonysmith94 Jan 29, 2025
c5a19d8
pls pickup .npmrc
petertonysmith94 Jan 29, 2025
da039a4
chore: set registry for changeset
petertonysmith94 Jan 29, 2025
004eaf3
fix: envs
petertonysmith94 Jan 29, 2025
71fe6d3
remove env
petertonysmith94 Jan 29, 2025
9ee8d1c
chore: finalize GitHub package publishing
petertonysmith94 Jan 31, 2025
0ebc269
Merge branch 'master' of github.com:FuelLabs/fuels-ts into ps/chore/p…
petertonysmith94 Jan 31, 2025
bacff82
disable whoami
petertonysmith94 Jan 31, 2025
2eeefc9
chore: need to alter the changeset config
petertonysmith94 Jan 31, 2025
98d5fb8
pls
petertonysmith94 Jan 31, 2025
ec1f5e8
chore: need to update all the changesets
petertonysmith94 Jan 31, 2025
df0d1e2
chore: added better comment
petertonysmith94 Feb 4, 2025
05a3c52
chore: removed (potentially unneeded envs)
petertonysmith94 Feb 4, 2025
a417844
chore: re-added envs
petertonysmith94 Feb 4, 2025
b90e415
chore: fix ci name
petertonysmith94 Feb 4, 2025
4db3de2
chore: removed potentially unneeded config
petertonysmith94 Feb 4, 2025
640c693
fix: names of organisation
petertonysmith94 Feb 4, 2025
de63cb0
chore: removed failing command
petertonysmith94 Feb 4, 2025
caf7d5e
chore: remove redundant action
petertonysmith94 Feb 4, 2025
f179583
chore: changing the script name
petertonysmith94 Feb 4, 2025
fb63043
chore: readd registry-url
petertonysmith94 Feb 4, 2025
b8ed5a2
fix: script name
petertonysmith94 Feb 4, 2025
bb4fbb2
pls deploy
petertonysmith94 Feb 4, 2025
3be5dba
chore: finalise PR
petertonysmith94 Feb 4, 2025
65a6f1f
chore: changeset
petertonysmith94 Feb 4, 2025
0e76997
chore: rollback unneeded changes
petertonysmith94 Feb 5, 2025
60a9b69
disable release
petertonysmith94 Feb 5, 2025
d92a164
Merge branch 'master' into ps/chore/publish-pr-to-github
nedsalk Feb 7, 2025
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
4 changes: 4 additions & 0 deletions .changeset/angry-pianos-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: migrate `pr` + `next` package publishing to GitHub Packages
5 changes: 4 additions & 1 deletion .github/actions/ci-setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inputs:
pnpm-version:
description: "PNPM version"
default: 9.4.0
registry-url:
description: "Registry URL"
default: "https://registry.npmjs.org"
runs:
using: "composite"
steps:
Expand All @@ -19,7 +22,7 @@ runs:
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
registry-url: "https://registry.npmjs.org"
registry-url: ${{ inputs.registry-url }}

- name: Setup PNPM
uses: pnpm/action-setup@v4
Expand Down
41 changes: 0 additions & 41 deletions .github/actions/pr-release/action.yaml

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/pr-release.yaml
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
arboleya marked this conversation as resolved.
Show resolved Hide resolved
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 }}
19 changes: 16 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,18 @@ jobs:
LATEST_RELEASE: ${{ env.LATEST_RELEASE }}
RELEASE_VERSION_HIGHER_THAN_LATEST: ${{ env.RELEASE_VERSION_HIGHER_THAN_LATEST }}

- name: Release to @next tag on npm
- name: Create .npmrc
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true'
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: Release to @next tag on GitHub Packages
if: github.ref_name == 'master' && steps.changesets.outputs.published != 'true'
run: |
git checkout master
Expand All @@ -105,12 +116,14 @@ jobs:
fi
pnpm changeset:next
git add .changeset/fuel-labs-ci.md
pnpm changeset version --snapshot next
pnpm changeset publish --tag next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_DEPLOY_TOKEN }}
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"

# ensure docs are always deployed after merge of changeset PR
- name: Get the last commit message and set env vars
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"prettier:format": "prettier --write packages --write apps/docs",
"verify:package-exports": "tsx ./scripts/verify-package-exports",
"changeset:publish": "tsx ./scripts/changeset/changeset-publish",
"changeset:next": "tsx ./scripts/changeset/changeset-next",
"changeset:next": "tsx ./scripts/changeset/changeset-next.mts",
"changeset:version-with-docs": "tsx ./scripts/changeset/changeset-version-with-docs",
"changeset:update-changelog": "tsx ./scripts/changeset/update-changelog.mts",
"changeset:get-latest-release": "tsx ./scripts/changeset/get-latest-release.mts",
Expand Down
84 changes: 84 additions & 0 deletions scripts/changeset/changeset-next.mts
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`);
4 changes: 0 additions & 4 deletions scripts/changeset/changeset-next.ts

This file was deleted.