Skip to content

Commit f1dc827

Browse files
feat: setup
1 parent 39f6d9d commit f1dc827

File tree

148 files changed

+21132
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+21132
-0
lines changed

.eslintrc.cjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
root: true,
3+
env: { browser: true, es2020: true },
4+
extends: [
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:react-hooks/recommended",
8+
"plugin:storybook/recommended",
9+
],
10+
ignorePatterns: ["dist", ".eslintrc.cjs"],
11+
parser: "@typescript-eslint/parser",
12+
plugins: ["react-refresh"],
13+
rules: {
14+
"react-refresh/only-export-components": [
15+
"warn",
16+
{ allowConstantExport: true },
17+
],
18+
},
19+
};

.github/depandabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/" # Location of package manifests
5+
schedule:
6+
interval: "daily"
7+
open-pull-requests-limit: 10 # Optional, limits the number of open PRs
8+
labels: ["dependencies"] # Optional, add labels to PRs
9+
groups:
10+
all-updates: # Group name
11+
patterns:
12+
- "*" # Group all updates into a single PR

.github/workflows/chromatic.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Name of our action
2+
name: 'Chromatic'
3+
# The event that will trigger the action
4+
on: push
5+
# What the action will do
6+
jobs:
7+
test:
8+
# The operating system it will run on
9+
runs-on: ubuntu-latest
10+
# The list of steps that the action will go through
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: 18
18+
# 👇 Add step to setup pnpm
19+
- uses: pnpm/action-setup@v2
20+
with:
21+
version: 8 # Use the pnpm version you're using locally
22+
# 👇 Use pnpm install instead of yarn
23+
- run: pnpm install
24+
- uses: chromaui/action@latest
25+
with:
26+
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
# 👇 Adds exitOnceUploaded flag to speed up CI
29+
exitOnceUploaded: true # Skip waiting for build results
30+
onlyChanged: true # Optional: only test changed components
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: Create Testing Candidate (TC)
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
create-tc:
10+
runs-on: ubuntu-latest
11+
env:
12+
GITHUB_TOKEN: ${{ secrets.GH_MABLE_OWNER_WRITE }}
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Install pnpm and dependencies
19+
run: |
20+
npm install -g pnpm
21+
pnpm install # Install dependencies, including tsup
22+
pnpm install --save-dev semver
23+
24+
- name: Build with tsup
25+
run: pnpm run build
26+
27+
- name: Set up Git
28+
run: |
29+
git config --global user.name 'github-actions'
30+
git config --global user.email 'github-actions@github.com'
31+
32+
- name: Determine Release Type
33+
id: determine-release-type
34+
uses: actions/github-script@v6
35+
with:
36+
script: |
37+
const commitMessage = await github.rest.repos.getCommit({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
ref: context.sha
41+
}).then(response => response.data.commit.message);
42+
43+
let releaseType = 'patch';
44+
const match = commitMessage.match(/\((major|minor|patch)\)$/);
45+
if (match) {
46+
releaseType = match[1];
47+
}
48+
49+
core.exportVariable('RELEASE_TYPE', releaseType);
50+
51+
- name: Print Release Type for Debugging
52+
run: echo "Release type is ${{ env.RELEASE_TYPE }}"
53+
54+
- name: Determine Next Version
55+
id: next_version
56+
run: |
57+
git fetch --tags
58+
git tag > all-tags.txt
59+
# Extract the base versions from tags, excluding the -tc suffix
60+
all_base_versions=$(grep -Eo '^[0-9]+\.[0-9]+\.[0-9]+' all-tags.txt | sort -V)
61+
if [ -z "$all_base_versions" ]; then
62+
LATEST_BASE_TAG="0.0.0"
63+
else
64+
LATEST_BASE_TAG=$(echo "$all_base_versions" | tail -n 1)
65+
fi
66+
# Increment the version based on the release type
67+
RELEASE_TYPE="${{ env.RELEASE_TYPE }}"
68+
NEXT_VERSION=$(npx semver "$LATEST_BASE_TAG" -i "$RELEASE_TYPE")
69+
TC_VERSION="$NEXT_VERSION-tc.$(date +%s)"
70+
echo "next_version=$TC_VERSION" >> $GITHUB_ENV
71+
72+
- name: Publish to GitHub Package Registry
73+
id: publish_to_gpr
74+
run: |
75+
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
76+
echo "@Mable-AI:registry=https://npm.pkg.github.com" >> ~/.npmrc
77+
git status
78+
git add package.json pnpm-lock.yaml src/components/index.tsx
79+
git commit -m "fix: version bump"
80+
npm version ${{ env.next_version }} --preid=alpha
81+
npm publish
82+
83+
- name: Tag and Push
84+
run: |
85+
git tag ${{ env.next_version }}
86+
git push origin ${{ env.next_version }}
87+
88+
- name: Run Chromatic
89+
uses: chromaui/action@latest
90+
with:
91+
exitZeroOnChanges: true
92+
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
93+
94+
- name: Create GitHub Release
95+
id: create_release
96+
uses: actions/github-script@v6
97+
with:
98+
script: |
99+
const nextVersion = process.env.next_version;
100+
const tagName = nextVersion;
101+
const owner = context.repo.owner;
102+
const repo = context.repo.repo;
103+
104+
// Get the latest tags for TC, RC, and release
105+
const tags = await github.rest.repos.listTags({
106+
owner,
107+
repo,
108+
per_page: 100
109+
});
110+
111+
const latestTCTag = tags.data.find(tag => tag.name.includes('-tc.') && tag.name !== tagName);
112+
const latestRCTag = tags.data.find(tag => tag.name.includes('-rc.') && tag.name !== tagName);
113+
const latestReleaseTag = tags.data.find(tag => !tag.name.includes('-tc.') && !tag.name.includes('-rc.') && tag.name !== tagName);
114+
115+
// Find the latest minor TC tag
116+
const currentMinorVersion = nextVersion.match(/^(\d+\.\d+)/)[1];
117+
const minorTCTags = tags.data.filter(tag => tag.name.includes('-tc.') && tag.name.startsWith(currentMinorVersion));
118+
const latestMinorTCTag = minorTCTags.sort((a, b) => {
119+
const [aVersion, aTC] = a.name.split('-tc.');
120+
const [bVersion, bTC] = b.name.split('-tc.');
121+
return parseInt(aTC) - parseInt(bTC);
122+
}).find(tag => tag.name !== tagName);
123+
124+
const createComparisonUrl = (base, head) => `https://github.com/${owner}/${repo}/compare/${base}...${head}`;
125+
126+
const diffs = [];
127+
if (latestTCTag) {
128+
diffs.push(`- [Diff from last TC](${createComparisonUrl(latestTCTag.name, tagName)})`);
129+
}
130+
if (latestMinorTCTag) {
131+
diffs.push(`- [Diff from last minor TC](${createComparisonUrl(latestMinorTCTag.name, tagName)})`);
132+
}
133+
if (latestRCTag) {
134+
diffs.push(`- [Diff from last RC](${createComparisonUrl(latestRCTag.name, tagName)})`);
135+
}
136+
if (latestReleaseTag) {
137+
diffs.push(`- [Diff from last Release](${createComparisonUrl(latestReleaseTag.name, tagName)})`);
138+
}
139+
140+
const body = `
141+
### Changes in this release:
142+
${diffs.length > 0 ? diffs.join('\n') : 'No previous tags found to compare.'}
143+
144+
### Commits:
145+
https://github.com/${owner}/${repo}/commits/${tagName}
146+
`;
147+
148+
await github.rest.repos.createRelease({
149+
owner,
150+
repo,
151+
tag_name: tagName,
152+
name: `Testing Candidate ${nextVersion}`,
153+
body,
154+
draft: false,
155+
prerelease: true,
156+
generate_release_notes: true
157+
});
158+
159+
- name: Cleanup Tag on Failure
160+
if: failure()
161+
run: |
162+
git tag -d ${{ env.next_version }}
163+
git push --delete origin ${{ env.next_version }}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: Promote Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
source_tag:
7+
description: "Tag to promote"
8+
required: true
9+
10+
jobs:
11+
promote:
12+
runs-on: ubuntu-latest
13+
env:
14+
WORKFLOW_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
with:
20+
token: ${{ secrets.WORKFLOW_TOKEN }}
21+
fetch-depth: 0 # Ensures we fetch all history
22+
23+
- name: Install pnpm and dependencies
24+
run: |
25+
npm install -g pnpm
26+
pnpm install # Install dependencies, including tsup
27+
28+
- name: Build with tsup
29+
run: pnpm run build
30+
31+
- name: Set up Git and GitHub CLI
32+
run: |
33+
git config --global user.name 'github-actions'
34+
git config --global user.email 'github-actions@github.com'
35+
echo "${{ secrets.WORKFLOW_TOKEN }}" | gh auth login --with-token
36+
37+
- name: Fetch tags and checkout the source tag
38+
run: |
39+
# Fetch all tags
40+
git fetch --tags
41+
# Checkout the source tag
42+
git checkout tags/${{ github.event.inputs.source_tag }}
43+
44+
- name: Determine new tag
45+
id: determine-new-tag
46+
run: |
47+
source_tag="${{ github.event.inputs.source_tag }}"
48+
if [[ "$source_tag" =~ -tc\. ]]; then
49+
BASE_TAG=$(echo "$source_tag" | sed 's/-tc\..*//')
50+
NEW_TAG="${BASE_TAG}-rc.$(date +%s)"
51+
echo "target_environment=RC" >> $GITHUB_ENV
52+
elif [[ "$source_tag" =~ -rc\. ]]; then
53+
BASE_TAG=$(echo "$source_tag" | sed 's/-rc\..*//')
54+
NEW_TAG="$BASE_TAG"
55+
echo "target_environment=Release" >> $GITHUB_ENV
56+
else
57+
echo "::error ::Unsupported source tag format"
58+
exit 1
59+
fi
60+
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
61+
62+
- name: Print New Tag for Debugging
63+
run: echo "New tag is ${{ env.NEW_TAG }}"
64+
65+
- name: Publish to GitHub Package Registry
66+
id: publish_to_gpr
67+
run: |
68+
echo "Publishing to GitHub Package Registry"
69+
echo "Target environment is ${{ env.target_environment }}"
70+
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
71+
echo "@Mable-AI:registry=https://npm.pkg.github.com" >> ~/.npmrc
72+
git status
73+
git add package.json pnpm-lock.yaml
74+
git commit -m "fix: version bump"
75+
if [[ "$target_environment" == "RC" ]]; then
76+
npm version $NEW_TAG --preid=beta
77+
elif [[ "$target_environment" == "Release" ]]; then
78+
npm version $NEW_TAG
79+
else
80+
echo "::error ::Unsupported source tag format"
81+
exit 1
82+
fi
83+
npm publish
84+
85+
- name: Push the new tag
86+
run: |
87+
# Create the new tag
88+
git tag $NEW_TAG
89+
# Push the new tag to the remote repository
90+
git push origin $NEW_TAG
91+
92+
- name: Run Chromatic
93+
uses: chromaui/action@latest
94+
with:
95+
exitZeroOnChanges: true
96+
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
97+
98+
- name: Print Environment Variables
99+
run: |
100+
echo "TARGET_BRANCH: $TARGET_BRANCH"
101+
echo "SOURCE_BRANCH: $SOURCE_BRANCH"
102+
103+
- name: Create GitHub Release
104+
id: create_release
105+
uses: actions/github-script@v6
106+
with:
107+
script: |
108+
const targetTag = process.env.NEW_TAG;
109+
const owner = context.repo.owner;
110+
const repo = context.repo.repo;
111+
const tags = await github.rest.repos.listTags({
112+
owner,
113+
repo,
114+
per_page: 100
115+
});
116+
const latestRCTag = tags.data.find(tag => tag.name.includes('-rc.') && tag.name !== targetTag);
117+
const latestReleaseTag = tags.data.find(tag => !tag.name.includes('-tc.') && !tag.name.includes('-rc.') && tag.name !== targetTag);
118+
const createComparisonUrl = (base, head) => `https://github.com/${owner}/${repo}/compare/${base}...${head}`;
119+
const diffs = [];
120+
if (latestRCTag) {
121+
diffs.push(`- [Diff from last RC](${createComparisonUrl(latestRCTag.name, targetTag)})`);
122+
}
123+
if (latestReleaseTag) {
124+
diffs.push(`- [Diff from last Release](${createComparisonUrl(latestReleaseTag.name, targetTag)})`);
125+
}
126+
const body = `
127+
### Changes in this release:
128+
${diffs.length > 0 ? diffs.join('\n') : 'No previous tags found to compare.'}
129+
### Commits:
130+
https://github.com/${owner}/${repo}/commits/${targetTag}
131+
`;
132+
await github.rest.repos.createRelease({
133+
owner,
134+
repo,
135+
tag_name: targetTag,
136+
name: `Release ${targetTag}`,
137+
body,
138+
draft: false,
139+
prerelease: ${{ env.target_environment == 'RC' }},
140+
generate_release_notes: true
141+
});
142+
143+
- name: Fetch Tag and Target Branch
144+
run: |
145+
git fetch origin ${{ env.TARGET_BRANCH }}
146+
git checkout ${{ env.TARGET_BRANCH }}
147+
git fetch origin tag ${{ github.event.inputs.source_tag }}
148+
149+
- name: Rebase Target Branch to Tag
150+
run: |
151+
git rebase --onto ${{ github.event.inputs.source_tag }} $(git rev-list -n 1 ${{ github.event.inputs.source_tag }}^) ${{ env.TARGET_BRANCH }}
152+
git push origin ${{ env.TARGET_BRANCH }} --force-with-lease
153+
154+
- name: Cleanup on failure
155+
if: failure()
156+
run: |
157+
gh release delete $NEW_TAG --yes
158+
gh api -X DELETE repos/${{ github.repository }}/git/refs/tags/$NEW_TAG

0 commit comments

Comments
 (0)