Upload v3 #23
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Commit | |
on: | |
push: | |
branches: | |
- master | |
- build-and-commit # For testing purposes | |
pull_request: | |
branches: | |
- master | |
- build-and-commit # For testing purposes | |
workflow_dispatch: | |
jobs: | |
check-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '21' | |
- name: Get current package version | |
id: current_version | |
run: echo "::set-output name=version::$(jq -r .version package.json)" | |
- name: Get base branch package version | |
run: | | |
git fetch origin master | |
BASE_VERSION=$(git show origin/master:package.json | jq -r .version) | |
echo "::set-output name=base_version::$BASE_VERSION" | |
id: base_version | |
- name: Compare versions | |
run: | | |
if [ "${{ steps.current_version.outputs.version }}" == "${{ steps.base_version.outputs.base_version }}" ]; then | |
echo "Package version has not been updated." | |
exit 1 | |
else | |
echo "Package version has been updated." | |
fi | |
build: | |
runs-on: ubuntu-latest | |
if: github.event_name != 'pull_request' || github.event.pull_request.merged == true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '21' | |
- name: Install dependencies | |
run: npm install | |
- name: Build project | |
run: npm run build | |
- name: Check for changes | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add . | |
if git diff-index --quiet HEAD; then | |
echo "No changes to commit" | |
else | |
git commit -m "Build: Commit changes after build" | |
git push | |
fi | |
test: | |
runs-on: ubuntu-latest | |
if: github.event_name != 'pull_request' || github.event.pull_request.merged == true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '21' | |
- name: Install dependencies | |
run: npm install | |
- name: Run Cypress tests | |
run: npm run test | |
- name: Upload screenshots | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: cypress-screenshots | |
path: cypress/screenshots | |
screenshots: | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create check run with screenshot links | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { GITHUB_RUN_ID, GITHUB_REPOSITORY } = process.env; | |
const artifactUrl = `https://github.com/${GITHUB_REPOSITORY}/suites/${GITHUB_RUN_ID}/artifacts`; | |
const checkRunId = context.runId; | |
await github.checks.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
name: 'Cypress Screenshots', | |
head_sha: context.sha, | |
status: 'completed', | |
conclusion: 'success', | |
output: { | |
title: 'Cypress Screenshots', | |
summary: `Cypress test screenshots are available [here](${artifactUrl}).`, | |
}, | |
}); | |