Release #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_run: | |
| workflows: ["Build"] | |
| types: [completed] | |
| branches: [release] | |
| workflow_dispatch: | |
| jobs: | |
| Build-and-Release: | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Print branch and commit info | |
| env: | |
| REF_NAME: ${{ github.ref_name }} | |
| HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} | |
| DEFAULT_SHA: ${{ github.sha }} | |
| EVENT_SHA: ${{ github.event.workflow_run.head_commit.id }} | |
| EVENT_MSG: ${{ github.event.workflow_run.head_commit.message }} | |
| run: | | |
| BRANCH="${HEAD_BRANCH:-$REF_NAME}" | |
| echo "branch=${BRANCH:-unset}" | |
| echo "sha=${EVENT_SHA:-$DEFAULT_SHA}" | |
| echo "msg=${EVENT_MSG:-event payload missing}" | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| - name: Print commit info from repo | |
| run: | | |
| git show -1 --pretty=format:'Commit SHA: %H%nCommit message: %B' | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run lint | |
| run: npm run lint | |
| - name: Check formatting | |
| run: npm run format-check | |
| - name: Build project | |
| run: npm run build | |
| - name: Install jq | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| - name: Get version | |
| id: version | |
| run: echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT | |
| - name: Print version | |
| run: | | |
| echo "Version: '${{ steps.version.outputs.version }}'" | |
| - name: Release to version dir | |
| run: | | |
| VERSION=${{ steps.version.outputs.version }} | |
| # Create version directory | |
| if [ -d "docs/app/$VERSION" ]; then | |
| rm -rf "docs/app/$VERSION" | |
| fi | |
| mkdir -p "docs/app/$VERSION/excel" | |
| # Copy dist/spa to docs/app/version/excel | |
| cp -r dist/spa/* "docs/app/$VERSION/excel/" | |
| - name: Release to current dir | |
| run: | | |
| # Update current | |
| rm -rf "docs/app/current/excel" | |
| mkdir -p "docs/app/current/excel" | |
| cp -r dist/spa/* "docs/app/current/excel/" | |
| - name: Commit and push changes | |
| env: | |
| PUSH_BRANCH: ${{ github.event.workflow_run.head_branch || github.ref_name }} | |
| run: | | |
| if [ -z "${PUSH_BRANCH}" ]; then | |
| echo "Cannot determine push target branch." | |
| exit 1 | |
| fi | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add docs/app/ | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "Release Single Page App files to GitHub pages (ver: ${{ steps.version.outputs.version }})" | |
| echo "Pushing to branch '${PUSH_BRANCH}'" | |
| git push origin HEAD:"${PUSH_BRANCH}" | |
| fi |