Skip to content

Deploy to Files Repo #3

Deploy to Files Repo

Deploy to Files Repo #3

Workflow file for this run

name: Deploy to Files Repo
on:
workflow_dispatch:
env:
PAGES_REPO: ThiruDev50/files
TARGET_PATH: devtools/genetom-clipsync
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout private repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build application
run: npm run build
- name: Clone public repository
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/${PAGES_REPO}.git pages-repo
cd pages-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Prepare deployment metadata
id: metadata
run: |
echo "commit_id=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "commit_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "datetime=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
echo "commit_message=$(git log -1 --pretty=%B | head -n 1)" >> $GITHUB_OUTPUT
- name: Create target directory if not exists
run: |
cd pages-repo
mkdir -p ${TARGET_PATH}
- name: Copy build files
run: |
cd pages-repo
rm -rf ${TARGET_PATH}/dist
cp -r ../dist ${TARGET_PATH}/
- name: Copy CHANGELOG.md
run: |
if [ -f CHANGELOG.md ]; then
cp CHANGELOG.md pages-repo/${TARGET_PATH}/
fi
- name: Create deployment.json
run: |
cd pages-repo/${TARGET_PATH}
cat > deployment.json <<EOF
{
"commitId": "${{ steps.metadata.outputs.commit_id }}",
"commitShort": "${{ steps.metadata.outputs.commit_short }}",
"branch": "${{ steps.metadata.outputs.branch }}",
"deployedAt": "${{ steps.metadata.outputs.datetime }}",
"commitMessage": "${{ steps.metadata.outputs.commit_message }}",
"repository": "${{ github.repository }}"
}
EOF
- name: Update deployment_history.json
run: |
cd pages-repo/${TARGET_PATH}
# Create new deployment entry
NEW_ENTRY=$(cat <<EOF
{
"commitId": "${{ steps.metadata.outputs.commit_id }}",
"commitShort": "${{ steps.metadata.outputs.commit_short }}",
"branch": "${{ steps.metadata.outputs.branch }}",
"deployedAt": "${{ steps.metadata.outputs.datetime }}",
"commitMessage": "${{ steps.metadata.outputs.commit_message }}"
}
EOF
)
# Check if deployment_history.json exists
if [ -f deployment_history.json ]; then
# Read existing history and prepend new entry
EXISTING=$(cat deployment_history.json)
echo "$EXISTING" | jq --argjson new "$NEW_ENTRY" '. = [$new] + .' > deployment_history.json
else
# Create new history file with first entry
echo "[$NEW_ENTRY]" | jq '.' > deployment_history.json
fi
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
cd pages-repo
git add ${TARGET_PATH}
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "Deploy ${{ steps.metadata.outputs.commit_short }} from ${{ steps.metadata.outputs.branch }} branch
Source commit: ${{ steps.metadata.outputs.commit_id }}
Branch: ${{ steps.metadata.outputs.branch }}
Message: ${{ steps.metadata.outputs.commit_message }}"
git push origin main
- name: Deployment summary
run: |
echo "### Deployment Successful! 🚀" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${{ steps.metadata.outputs.commit_short }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** \`${{ steps.metadata.outputs.branch }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Deployed at:** ${{ steps.metadata.outputs.datetime }}" >> $GITHUB_STEP_SUMMARY
echo "**Target:** [${PAGES_REPO}/${TARGET_PATH}](https://github.com/${PAGES_REPO}/tree/main/${TARGET_PATH})" >> $GITHUB_STEP_SUMMARY