Files
NodeTest/.github/workflows/Build.yml
Cyanoure 0c4aec4886
All checks were successful
Build and Save Artifact / build (pull_request) Successful in 13s
Actions: Update build branch name
2024-09-15 17:38:36 +02:00

68 lines
1.9 KiB
YAML

name: Build and Save Artifact
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3
# Set up Node.js environment
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '22'
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
# Initialize build branch
- name: Initialize build branch
run: |
SOURCE_BRANCH_NAME=${{ steps.extract_branch.outputs.branch }}
git config --global user.name 'Git Workflow Bot'
git config --global user.email 'noreply@kozelkaricsi.hu'
git fetch origin
git checkout ${SOURCE_BRANCH_NAME}
BRANCH_NAME="autobuild/${SOURCE_BRANCH_NAME}"
git fetch origin $BRANCH_NAME --unshallow || true # Allow failure if branch doesn't exist
git switch $BRANCH_NAME || git switch -c $BRANCH_NAME
git merge ${SOURCE_BRANCH_NAME} -m "Update branch [skip ci]"
rm -rf dist
# Install dependencies
- name: Install dependencies
run: npm install
# Build the project
- name: Run npm build
run: npm run build
# Commit build files
- name: Commit build files to build branch
run: |
git add -f dist
git commit -m "Build" || echo "Nothing to commit"
git push origin HEAD --force # Push to the current branch
# Upload the build directory as an artifact
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: |
./dist
./package.json