Skip to content

47 workflow merge main check for pull requests #39

47 workflow merge main check for pull requests

47 workflow merge main check for pull requests #39

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-main-merged-in-pr:
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: Check if main is merged into PR branch
run: |
# Set variables for main and PR commits
MAIN_COMMIT=$(git rev-parse origin/main)
PR_COMMIT=$(git rev-parse HEAD)
# Create a temporary branch for comparison
git checkout -b temp-main $MAIN_COMMIT
# Merge PR changes into the temporary branch
git merge --no-commit --no-ff $PR_COMMIT
# Check if there are changes other than those in the PR
if git diff --exit-code; then
echo "PR branch is up-to-date with the main branch and contains only PR changes."
else
echo "Error: The PR branch contains changes not in the main branch or is not up-to-date."
exit 1
fi
linting:
runs-on: ubuntu-latest
needs: check-main-merged-in-pr
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-main-merged-in-pr]
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