Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

# Lints, tests, and builds the app on every PR/push touching dev or main.
# Acts as the required status check before merging.

on:
pull_request:
branches:
- dev
- main
push:
branches:
- dev
- main

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Run tests
run: npm run test:run

- name: Build
run: npm run build
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release

# Publishes a GitHub release whenever a PR is merged (or a push lands) on main.
# validate-version.yml guarantees the root `version` file was already bumped
# before the merge, so the tag here is always new.

on:
push:
branches:
- main
paths-ignore:
- '.github/workflows/**'
- '**/*.md'
- '**/*.MD'
- '.gitignore'

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Read version
id: version
run: echo "version=$(tr -d ' \n' < version)" >> "$GITHUB_OUTPUT"

- name: Package build output
run: |
cd dist
zip -r "../pokesearch-${{ steps.version.outputs.version }}.zip" .

- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
generate_release_notes: true
files: pokesearch-${{ steps.version.outputs.version }}.zip
draft: false
prerelease: false
make_latest: true
159 changes: 159 additions & 0 deletions .github/workflows/validate-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: Validate Version

# Gate for PRs into main: the root `version` file must be bumped above main's
# current value before merge, since a merge to main auto-publishes a release
# tagged from that file (see release.yml).

on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
paths-ignore:
- '.github/workflows/**'
- '**/*.md'
- '**/*.MD'
- '.gitignore'

permissions:
contents: read
pull-requests: write

jobs:
check-version:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Fetch base branch
run: git fetch origin ${{ github.base_ref }}

- name: Check if version file was modified
id: check_version
run: |
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"

if echo "$CHANGED_FILES" | grep -q "^version$"; then
echo "version_changed=true" >> "$GITHUB_OUTPUT"
else
echo "version_changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Read current version
if: steps.check_version.outputs.version_changed == 'true'
id: current_version
run: |
VERSION=$(tr -d ' \n' < version)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Check if release tag already exists
if: steps.check_version.outputs.version_changed == 'true'
id: check_tag
run: |
TAG="v${{ steps.current_version.outputs.version }}"
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "${TAG}$"; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi

- name: Read base branch version
if: steps.check_version.outputs.version_changed == 'true'
id: base_version
run: |
if git cat-file -e origin/${{ github.base_ref }}:version 2>/dev/null; then
BASE_VERSION=$(git show origin/${{ github.base_ref }}:version | tr -d ' \n')
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "version=$BASE_VERSION" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi

- name: Compare versions
if: steps.check_version.outputs.version_changed == 'true' && steps.base_version.outputs.exists == 'true'
id: compare
run: |
CURRENT="${{ steps.current_version.outputs.version }}"
BASE="${{ steps.base_version.outputs.version }}"

compare_versions() {
local current=$1 base=$2
IFS='.' read -ra CURRENT_PARTS <<< "$current"
IFS='.' read -ra BASE_PARTS <<< "$base"
local max_len=${#CURRENT_PARTS[@]}
[ ${#BASE_PARTS[@]} -gt "$max_len" ] && max_len=${#BASE_PARTS[@]}
for ((i=0; i<max_len; i++)); do
c=${CURRENT_PARTS[$i]:-0}
b=${BASE_PARTS[$i]:-0}
if [ "$c" -gt "$b" ]; then return 0; fi
if [ "$c" -lt "$b" ]; then return 1; fi
done
return 2
}

compare_versions "$CURRENT" "$BASE"
case $? in
0) echo "result=increased" >> "$GITHUB_OUTPUT"; echo "should_fail=false" >> "$GITHUB_OUTPUT" ;;
2) echo "result=unchanged" >> "$GITHUB_OUTPUT"; echo "should_fail=true" >> "$GITHUB_OUTPUT" ;;
1) echo "result=decreased" >> "$GITHUB_OUTPUT"; echo "should_fail=true" >> "$GITHUB_OUTPUT" ;;
esac

- name: Comment on PR
if: always()
uses: actions/github-script@v7
with:
script: |
const versionChanged = '${{ steps.check_version.outputs.version_changed }}';
const compareResult = '${{ steps.compare.outputs.result }}';
const currentVersion = '${{ steps.current_version.outputs.version }}';
const baseVersion = '${{ steps.base_version.outputs.version }}';
const baseExists = '${{ steps.base_version.outputs.exists }}';
const tagExists = '${{ steps.check_tag.outputs.exists }}';

let message = '';

if (versionChanged === 'false') {
message = `❌ **Version File Not Updated**\n\nThe root \`version\` file was not modified in this PR. Please bump it before merging to \`main\`.`;
} else if (tagExists === 'true') {
message = `❌ **Release Tag Already Exists**\n\nVersion \`${currentVersion}\` maps to tag \`v${currentVersion}\`, which already exists. Please bump the version further.`;
} else if (baseExists === 'false') {
message = `⚠️ **New Version File**\n\nThe \`version\` file doesn't exist on \`main\` yet. Creating it with version \`${currentVersion}\`.`;
} else if (compareResult === 'increased') {
message = `✅ **Version Update Detected**\n\nVersion bumped from \`${baseVersion}\` to \`${currentVersion}\`.`;
} else if (compareResult === 'unchanged') {
message = `❌ **Version Unchanged**\n\nThe \`version\` file was modified but still reads \`${currentVersion}\`. Please bump it.`;
} else if (compareResult === 'decreased') {
message = `❌ **Version Decreased**\n\nVersion dropped from \`${baseVersion}\` to \`${currentVersion}\`. Versions must only increase.`;
}

if (message) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
}

- name: Fail if version not bumped
if: steps.check_version.outputs.version_changed == 'false'
run: |
echo "::error::The root 'version' file must be updated in this PR before merging to main."
exit 1

- name: Fail if release tag already exists
if: steps.check_version.outputs.version_changed == 'true' && steps.check_tag.outputs.exists == 'true'
run: |
echo "::error::Release tag v${{ steps.current_version.outputs.version }} already exists. Bump the version."
exit 1

- name: Fail if version comparison failed
if: steps.compare.outputs.should_fail == 'true'
run: |
echo "::error::Version validation failed: ${{ steps.compare.outputs.result }}."
exit 1
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ selenium-debug.log

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.16.0
24.18.0
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@

## Project setup
```
yarn install
npm install
```

### Compiles and hot-reloads for development
```
yarn run serve
npm run dev
```

### Compiles and minifies for production
```
yarn run build
npm run build
```

### Run your tests
### Locally preview the production build
```
yarn run test
npm run preview
```

### Lints and fixes files
### Run your tests
```
yarn run lint
npm test
```

### Run your end-to-end tests
### Run your tests once (CI mode)
```
yarn run test:e2e
npm run test:run
```

### Run your unit tests
### Lints files
```
yarn run test:unit
npm run lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
See the [Vite configuration reference](https://vite.dev/config/).
16 changes: 15 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import pluginVue from 'eslint-plugin-vue'
import js from '@eslint/js'

export default [
{ ignores: ['dist/**', 'dist-electron/**', 'coverage/**'] },
js.configs.recommended,
...pluginVue.configs['flat/essential']
...pluginVue.configs['flat/essential'],
{
files: ['**/__tests__/**', '**/*.spec.js'],
languageOptions: {
globals: {
describe: 'readonly',
it: 'readonly',
expect: 'readonly',
vi: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly'
}
}
}
]
Loading
Loading