Skip to content

feat(dev): build dev preview site on build #1138

feat(dev): build dev preview site on build

feat(dev): build dev preview site on build #1138

Workflow file for this run

name: Build and Deploy
on: push
env:
CI: true
NODE_VER: 20
NETLIFY_SITE_ID: 89194942-bd48-4c23-a181-7e489c17eabc
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VER }}
- uses: bahmutov/npm-install@v1
- name: prettier
run: npx prettier '**/*.{js?(on|x),ts?(x),y?(a)ml,graphql,md,css}' --check
- name: typescript
run: npx tsc --noEmit
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VER }}
- uses: bahmutov/npm-install@v1
- name: build
run: npm run build
- name: build package
run: npm version --no-git-tag-version 0.0.0-${{ github.sha }} && npm pack
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: build
path: dist
- name: Upload package
uses: actions/upload-artifact@v3
with:
name: react-image-0.0.0-${{ github.sha }}.tgz
path: react-image-0.0.0-${{ github.sha }}.tgz
test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VER }}
- uses: bahmutov/npm-install@v1
- name: test
run: npm test
- name: download build artifact
uses: actions/download-artifact@v3
with:
name: build
path: dist
- name: test built libs
run: npm run test:dist
- name: Deploy visual tests to Netlify
uses: nwtgck/actions-netlify@v2
id: deploy-to-netlify
with:
publish-dir: dist/dev
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: '[${{ github.ref_name }}@${{ env.GIT_SHORT_REVISION }}] ${{ env.GIT_SHORT_COMMIT_MESSAGE }}'
enable-pull-request-comment: false
enable-commit-comment: false
enable-commit-status: false
# Use custom alias for non master branch Deploy Previews only
alias: ${{ github.ref_name != 'master' && env.RUN_NAME || '' }}
github-deployment-environment: '[${{ env.GIT_BRANCH }}] visual tests'
fails-without-credentials: true
production-deploy: ${{ github.ref_name == 'master' }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ env.NETLIFY_SITE_ID }}
deploy:
runs-on: ubuntu-latest
needs: [lint, test]
if: ${{ github.ref_name == 'master' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VER }}
- uses: bahmutov/npm-install@v1
- name: setup .npmrc
run: npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: download build artifact
uses: actions/download-artifact@v3
with:
name: build
path: dist
- name: check if package is newer than the published version
id: checkPublish
run: echo "::set-output name=shouldPublish::`npm run -s isNewerThanPublished`"
- name: publish release package if needed
if: steps.checkPublish.outputs.shouldPublish == 'true'
run: npm publish