diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 47befa8..c90a64c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,20 +2,18 @@ name: Lints on: pull_request: - branches: - - main jobs: lint: name: Lint - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: '20.x' - name: Install dependencies run: yarn diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 879006d..c078dc8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,35 +4,56 @@ on: push: branches: - main - workflow_run: - workflows: ['Lints', 'Coverage'] - types: - - completed + - release concurrency: ${{ github.workflow }}-${{ github.ref }} jobs: release: name: Release - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 + permissions: + contents: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 16 - cache: 'yarn' - cache-dependency-path: '**/yarn.lock' - - - uses: actions/setup-node@v1 - with: - node-version: 16 + node-version: '20.x' registry-url: 'https://registry.npmjs.org' - - name: Config git user + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run build + run: yarn lerna run build + + - name: Run test + run: yarn test + + - name: Configure git user run: | git config --global user.name "${{ github.actor }}" git config --global user.email "${{ github.actor }}@users.noreply.github.com" - - run: yarn install --frozen-lockfile + - name: Bump version and create release + run: | + if [ "${{ github.ref_name }}" == "main" ]; then + yarn lerna version --yes --conventional-commits --conventional-prerelease --exact --create-release github --preid beta --loglevel silly + else + yarn lerna version --yes --conventional-commits --conventional-graduate --exact --create-release github --loglevel silly + fi + env: + GH_TOKEN: ${{ github.token }} + + - name: Publish to NPM + run: | + if [ "${{ github.ref_name }}" == "main" ]; then + yarn lerna publish from-package --yes --no-private --loglevel silly --preid beta --dist-tag beta + else + yarn lerna publish from-package --yes --no-private --loglevel silly + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/sync-main-branch.yml b/.github/workflows/sync-main-branch.yml new file mode 100644 index 0000000..b7436b4 --- /dev/null +++ b/.github/workflows/sync-main-branch.yml @@ -0,0 +1,38 @@ +name: Sync main with release + +on: + push: + branches: + - main + +jobs: + sync-main-branch: + runs-on: ubuntu-22.04 + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Create PR from release to main + env: + GH_TOKEN: ${{ github.token }} + run: | + # Check if a pull request already exists from release to main + pr_url=$(gh pr list --head release --base main --json url --jq '.[0].url') + + if [ -n "$pr_url" ]; then + echo "PR already exists: $pr_url" + else + pr_url=$(gh pr create \ + --head release \ + --base main \ + --title "[skip ci][skip release] Sync main with the release branch" \ + --body "Auto-created pull request to merge changes from release into main." + ) + echo "Created PR: $pr_url" + fi + + # Attempt to merge the pull request (Fails, investigate later) + # gh pr merge "$pr_url" --merge --auto \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87d7db3..f8806ce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,6 @@ name: Test on: - push: pull_request: jobs: @@ -9,34 +8,21 @@ jobs: name: Test runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 + - uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: '20.x' - name: Install dependencies run: yarn - - name: Run test over the merged changes - run: | - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git config --global user.name "github-actions[bot]" - git checkout $GITHUB_BASE_REF - git merge --no-commit --no-edit ${{ github.event.pull_request.head.sha }} - yarn - yarn lerna run build - yarn test - if: github.event_name == 'pull_request' + - name: Run build + run: yarn lerna run build - - name: Test - run: | - yarn lerna run build - yarn test - if: github.event_name != 'pull_request' + - name: Run test + run: yarn test - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 \ No newline at end of file + uses: codecov/codecov-action@v3 diff --git a/lerna.json b/lerna.json index 38dcea9..d3e1e12 100644 --- a/lerna.json +++ b/lerna.json @@ -5,8 +5,8 @@ "useNx": true, "command": { "version": { - "message": "chore(release): Publish 🚀 [ci publish]", - "allowBranch": ["main"], + "message": "chore(release): [skip ci] Publish 🚀", + "allowBranch": ["main", "release"], "conventional-commits": true, "create-release": "github" }