Skip to content

Commit

Permalink
Create web-build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar-gg authored Sep 27, 2024
1 parent 193ec37 commit 0dd7008
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/web-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Node.js build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env: # Define environment variables at the workflow level
PERSONAL_ACCOUNT: roborregosteam

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npm run build

check-and-fork:
runs-on: ubuntu-latest
if: ${{ github.repository_owner != env.PERSONAL_ACCOUNT}}
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Check if repo exists
id: check_repo
run: |
REPO_NAME="${{ github.event.repository.name }}"
OWNER_NAME="${{ env.PERSONAL_ACCOUNT }}"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/${OWNER_NAME}/${REPO_NAME})
if [ "$RESPONSE" -eq 404 ]; then
echo "Repository does not exist."
echo "fork_repo=true" >> $GITHUB_ENV
else
echo "Repository exists."
echo "fork_repo=false" >> $GITHUB_ENV
fi
- name: Fork the repository if it does not exist
if: env.fork_repo == 'true'
run: |
curl -L -X POST \
-H "Authorization: Bearer ${{ secrets.RBRGS_TEAM_GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/forks

0 comments on commit 0dd7008

Please sign in to comment.