Skip to content

Build and Push to Folder Overview #31

Build and Push to Folder Overview

Build and Push to Folder Overview #31

name: Build and Push to Folder Overview
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
inputs:
tag:
description: "Tag to build"
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Checkout folder-notes repository
- name: Checkout folder-notes
uses: actions/checkout@v3
with:
repository: LostPaul/obsidian-folder-notes
fetch-depth: 0
submodules: recursive
path: folder-notes
# Install dependencies and run the fv-build process
- name: Run npm install and build in folder-notes
run: |
cd folder-notes
npm install
npm run fv-build
# Verify that the built files exist
- name: Check built files
run: |
ls -la folder-notes/src/obsidian-folder-overview/
# Checkout folder-overview repository on the main branch
- name: Checkout folder-overview
uses: actions/checkout@v3
with:
repository: LostPaul/obsidian-folder-overview
token: ${{ secrets.PAT }}
ref: main # Ensures we are on the main branch
path: folder-overview
# Ensure we're on the main branch
- name: Ensure we are on main branch
run: |
cd folder-overview
git checkout main || git checkout -b main
# Copy the built files from folder-notes to folder-overview
- name: Copy built files to folder-overview
run: |
cp folder-notes/src/obsidian-folder-overview/main.js \
folder-notes/src/obsidian-folder-overview/styles.css folder-overview/
# Commit and push built files only if they changed
- name: Commit and push built files
run: |
cd folder-overview
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add main.js styles.css
# Only commit if there are changes
if git diff --cached --quiet; then
echo "No changes to commit."
else
git commit -m "Add built files for release"
git push origin main
fi
# Trigger release workflow in folder-overview
- name: Trigger release workflow in folder-overview
run: |
curl -X POST -H "Authorization: token ${{ secrets.PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/LostPaul/obsidian-folder-overview/actions/workflows/release.yaml/dispatches \
-d '{"ref": "main", "inputs": {"tag": "${{ github.ref_name }}"}}'
cleanup:
needs: build-and-push
runs-on: ubuntu-latest
steps:
# Checkout folder-overview again for cleanup
- name: Checkout folder-overview for cleanup
uses: actions/checkout@v3
with:
repository: LostPaul/obsidian-folder-overview
token: ${{ secrets.PAT }}
ref: main
path: folder-overview
# Remove built files after release
- name: Remove built files after release
run: |
cd folder-overview
git rm -f main.js styles.css || true
git commit -m "Cleanup built files after release" || echo "No changes to commit"
git push origin main || echo "No changes to push"