Skip to content

Commit

Permalink
chore: setup ci workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 31, 2024
0 parents commit a8cdd7b
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and Release

on:
push:
tags:
- '202[0-9][0-9][0-9][0-9][0-9].[0-9]*'

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
files: |
dist/* # Adjust this path based on your build output
39 changes: 39 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Create Tag on Sync Merge

on:
pull_request:
types: [closed]
branches:
- main

jobs:
tag:
# Only run if PR was merged (not just closed) and it was our sync PR
if: |
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref == 'sync/portal-frontend'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create and push tag
run: |
DATE=$(date +%Y%m%d)
# Get latest tag for today
LATEST_TAG=$(git tag -l "${DATE}.*" | sort -V | tail -n 1)
if [ -z "$LATEST_TAG" ]; then
NEW_TAG="${DATE}.1"
else
COUNTER=$(echo $LATEST_TAG | cut -d. -f2)
NEW_TAG="${DATE}.$((COUNTER + 1))"
fi
# Create and push tag
git tag $NEW_TAG
git push origin $NEW_TAG
112 changes: 112 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Sync from Monorepo

on:
repository_dispatch:
types: [portal-frontend-update]
workflow_dispatch:
inputs:
source_sha:
description: 'Source commit SHA (optional)'
required: false
source_ref:
description: 'Source ref (optional)'
required: false

jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Detect default branch
- name: Get default branch
id: default-branch
run: |
DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)
echo "name=$DEFAULT_BRANCH" >> $GITHUB_OUTPUT
- name: Set source ref
id: set-ref
run: |
SOURCE_SHA="${{ github.event.client_payload.source_sha || github.event.inputs.source_sha }}"
SOURCE_REF="${{ github.event.client_payload.source_ref || github.event.inputs.source_ref || 'develop' }}"
if [ -z "$SOURCE_SHA" ]; then
echo "ref=$SOURCE_REF" >> $GITHUB_OUTPUT
echo "source_desc=$SOURCE_REF branch" >> $GITHUB_OUTPUT
else
echo "ref=$SOURCE_SHA" >> $GITHUB_OUTPUT
echo "source_desc=commit $SOURCE_SHA" >> $GITHUB_OUTPUT
fi
- name: Clone and prepare monorepo
run: |
# Full clone to preserve history
git clone https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/lumeweb/web source
cd source
# Checkout desired ref
git checkout ${{ steps.set-ref.outputs.ref }}
# Extract portal-frontend history to a branch
git subtree split -P apps/portal-frontend -b portal-frontend-split
# Create a temporary remote
cd ..
git remote add monorepo ./source
git fetch monorepo portal-frontend-split
- name: Sync changes
id: sync
run: |
# Always work on the sync branch
git checkout sync/portal-frontend 2>/dev/null || git checkout -b sync/portal-frontend
# Try to merge the subtree while preserving history
if git merge --no-commit --allow-unrelated-histories temp/portal-frontend-split; then
# Check if there are actual changes
if git status --porcelain | grep .; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
# Complete the merge
git add .
git commit -m "sync: Update from monorepo ${{ steps.set-ref.outputs.source_desc }}"
else
# No changes to commit
git merge --abort || true
echo "changes_detected=false" >> $GITHUB_OUTPUT
fi
else
# Merge failed
git merge --abort || true
echo "changes_detected=false" >> $GITHUB_OUTPUT
exit 1
fi
- name: Push changes and update PR
if: steps.sync.outputs.changes_detected == 'true'
run: |
git push -f origin sync/portal-frontend
- name: Create or Update Pull Request
if: steps.sync.outputs.changes_detected == 'true'
uses: peter-evans/create-pull-request@v5
with:
title: "chore: sync portal-frontend from upstream"
body: |
Automated sync from monorepo ${{ steps.set-ref.outputs.source_desc }}
This PR includes all related commit history from the portal-frontend directory.
This is an automatically updating PR that keeps the portal-frontend in sync with upstream.
branch: "sync/portal-frontend"
delete-branch: false
base: ${{ steps.default-branch.outputs.name }} # Auto-detected default branch
labels: |
sync
automated

0 comments on commit a8cdd7b

Please sign in to comment.