From f042e9ed89acdc04de2741a0a7ee920bfa6ec714 Mon Sep 17 00:00:00 2001 From: Pontus Abrahamsson Date: Sun, 29 Dec 2024 10:56:47 +0100 Subject: [PATCH] Feature/ci (#31) * wip * Update version * Trigger build * Trigger build * Trigger build * Trigger build * Trigger build * Update readme --- .github/workflows/ci.yml | 104 ++++++++++++++++++++++++----- packages/cli/src/commands/clean.ts | 10 ++- packages/cli/src/commands/diff.ts | 5 +- packages/react-email/README.md | 2 + 4 files changed, 103 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90b51e2..0fcf1e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,7 @@ on: push: + branches: + - main jobs: test: @@ -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 }} diff --git a/packages/cli/src/commands/clean.ts b/packages/cli/src/commands/clean.ts index 90addc0..c9b0833 100644 --- a/packages/cli/src/commands/clean.ts +++ b/packages/cli/src/commands/clean.ts @@ -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( @@ -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( diff --git a/packages/cli/src/commands/diff.ts b/packages/cli/src/commands/diff.ts index a844aef..b83bf7c 100644 --- a/packages/cli/src/commands/diff.ts +++ b/packages/cli/src/commands/diff.ts @@ -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}`, { diff --git a/packages/react-email/README.md b/packages/react-email/README.md index f99dce5..884bc42 100644 --- a/packages/react-email/README.md +++ b/packages/react-email/README.md @@ -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!",