Skip to content

Merge pull request #56 from Sillen00/47-workflow-merge-main-check-for… #54

Merge pull request #56 from Sillen00/47-workflow-merge-main-check-for…

Merge pull request #56 from Sillen00/47-workflow-merge-main-check-for… #54

Workflow file for this run

name: Linting, prettier and Testing
on: #this workflow runs on pull requests and pushes to main or master
pull_request:
branches: [main, master]
push:
branches: [main, master]
#this is a list of all jobs
jobs:
check-pr-sync-with-main:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
- name: Create and checkout a temporary branch from main
run: |
git fetch origin main
git checkout -b temp-branch origin/main
- name: Merge PR branch into temporary branch
run: |
git merge ${{ github.event.pull_request.head.sha }} --no-edit || true
- name: Check for differences
run: |
if git diff --exit-code ${{ github.event.pull_request.head.sha }} temp-branch; then
echo "No differences found. The PR branch is up-to-date with the latest main branch."
else
echo "Differences found. The PR branch is not up-to-date with the latest main branch."
exit 1
fi
linting:
runs-on: ubuntu-latest
needs: check-pr-sync-with-main
steps:
- name: Checkout #checks out our current branch so this runner has the latest code
uses: actions/checkout@v4 #uses means that it is a pre-defined action supplied by GitHub.
- name: Setup Node
uses: actions/setup-node@v3 #this is also a pre-defined action
with:
node-version: 20
- name: NPM Install #we now need to install all our dependencies in this environment
run: npm ci #npm clean install - does not write to package.json
- name: Run linting
run: npm run lint
- name: Run prettier
run: npm run prettierW
testing: #name of first job
runs-on: ubuntu-latest #sets the env which this job runs on
needs: [linting, check-pr-sync-with-main]
steps: #defines the steps necessary
- name: Checkout #checks out our current branch so this runner has the latest code
uses: actions/checkout@v4 #uses means that it is a pre-defined action supplied by GitHub.
- name: Setup Node
uses: actions/setup-node@v3 #this is also a pre-defined action
with:
node-version: 20
- name: NPM Install #we now need to install all our dependencies in this environment
run: npm ci #npm clean install - does not write to package.json
- name: Run tests #if npm test throws and error this workflow fails.
run: npm test