Skip to content

Commit

Permalink
Feature/ci (#31)
Browse files Browse the repository at this point in the history
* wip

* Update version

* Trigger build

* Trigger build

* Trigger build

* Trigger build

* Trigger build

* Update readme
  • Loading branch information
pontusab authored Dec 29, 2024
1 parent 15a59e2 commit f042e9e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 18 deletions.
104 changes: 89 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
on:
push:
branches:
- main

jobs:
test:
Expand All @@ -12,21 +14,93 @@ jobs:
bun-version: latest
- name: Install dependencies
run: bun install
- name: 🔍 Run type checking
run: bun run typecheck
# - name: 🚨 Run linting
# run: bun run lint
- name: 🧪 Run unit tests
run: bun run test

# translate:
# name: Run translation
# runs-on: ubuntu-latest
# permissions:
# actions: write
# contents: write
# pull-requests: write
# steps:
# - uses: actions/checkout@v4
# - name: Languine
# uses: midday-ai/languine@main
# env:
# GH_TOKEN: ${{ github.token }}
# with:
# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
publish-cli:
name: Publish CLI
if: contains(github.event.head_commit.modified, 'packages/cli/')
needs: [test]
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build
working-directory: packages/cli
run: bun run build
- name: Get version
id: get_version
working-directory: packages/cli
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
echo "new_version=$(npx semver ${CURRENT_VERSION} -i patch)" >> $GITHUB_OUTPUT
- name: Update version
working-directory: packages/cli
run: npm version ${{ steps.get_version.outputs.new_version }} --no-git-tag-version
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get_version.outputs.new_version }}
name: Release (languine) v${{ steps.get_version.outputs.new_version }}
generate_release_notes: true
- name: Setup NPM Auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Publish to NPM
working-directory: packages/cli
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-react-email:
name: Publish React Email
if: contains(github.event.head_commit.modified, 'packages/react-email/')
needs: [test]
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build
working-directory: packages/react-email
run: bun run build
- name: Get version
id: get_version
working-directory: packages/react-email
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
echo "new_version=$(npx semver ${CURRENT_VERSION} -i patch)" >> $GITHUB_OUTPUT
- name: Update version
working-directory: packages/react-email
run: npm version ${{ steps.get_version.outputs.new_version }} --no-git-tag-version
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get_version.outputs.new_version }}
name: Release (@languine/react-email) v${{ steps.get_version.outputs.new_version }}
generate_release_notes: true
- name: Setup NPM Auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Publish to NPM
working-directory: packages/react-email
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
10 changes: 8 additions & 2 deletions packages/cli/src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export async function clean() {
// Process each file format and pattern
for (const [format, { include }] of Object.entries(config.files)) {
for (const pattern of include) {
const sourcePath = pattern.replace("[locale]", source);
const sourcePath =
typeof pattern === "string"
? pattern.replace("[locale]", source)
: pattern.from.replace("[locale]", source);

// Read source file to get reference keys
const sourceContent = await fs.readFile(
Expand All @@ -37,7 +40,10 @@ export async function clean() {

// Clean each target locale file
for (const locale of targets) {
const targetPath = pattern.replace("[locale]", locale);
const targetPath =
typeof pattern === "string"
? pattern.replace("[locale]", locale)
: pattern.from.replace("[locale]", locale);

try {
const targetContent = await fs.readFile(
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/commands/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export async function diff() {
const sourceLocale = config.locale.source;
const [fileFormat] = Object.keys(config.files);
const sourcePattern = config.files[fileFormat].include[0];
const sourcePath = sourcePattern.replace("[locale]", sourceLocale);
const sourcePath =
typeof sourcePattern === "string"
? sourcePattern.replace("[locale]", sourceLocale)
: sourcePattern.from.replace("[locale]", sourceLocale);

// Get git diff for source file
const diff = execSync(`git diff HEAD -- ${sourcePath}`, {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-email/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export function WelcomeEmail({ locale, name }) {

### Translation files (en.json)

Add your translation files in the `locales` folder.

```json
{
"preview": "Welcome to our app!",
Expand Down

0 comments on commit f042e9e

Please sign in to comment.