Skip to content

Master

Master #17

Workflow file for this run

name: ESLint Check
on:
workflow_dispatch:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
permissions:
pull-requests: write
contents: write
jobs:
lint-and-deploy:
name: Run ESLint check and deploy Preview
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: install all the dependencies
run: npm install
- name: Run ESLint test
run: npm run lint:strict
continue-on-error: true
id: eslint
- name: block PR if ESLint fails
continue-on-error: true
if: steps.eslint.outcome == 'failure'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.VAI }}
script: |
github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
event: 'REQUEST_CHANGES',
body: 'ESLint check failed. Please fix all linting issues (including warnings) before merging.'
})
- name: check for ESLint result
if: steps.eslint.outcome == 'failure'
run: |
echo "ESLint found issues. Failing the workflow."
exit 1
- name: setup NodeJS for Build
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- name: install all Dependencies
run: npm ci
- name: build Project from React Files
run: npm run build
- name: create _redirects file
run: echo "/healthcare/* /index.html 200" > build/_redirects
- name: install Netlify CLI
run: npm install [email protected] -g
- name: deploy to Netlify Preview page to check what change has been made by contributor
continue-on-error: true
id: netlify_deploy
run: |
netlify deploy \
--dir build \
--site ${{ secrets.NETLIFY_SITE_ID }} \
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
--json \
--alias "healthcare-${{ github.actor }}" \
> deploy_output.json
- name: Generate URL Preview
id: url_preview
run: |
NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json)
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_ENV"
- name: Comment URL Preview on PR
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const previewUrl = process.env.NETLIFY_PREVIEW_URL;
const issue_number = context.issue.number;
const username = context.actor;
if (previewUrl) {
await github.rest.issues.createComment({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `@${username} your preview URL has been generated : ${previewUrl}`
});
} else {
await github.rest.issues.createComment({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Deployment failed or no preview URL available for ${username}.`
});
}