add tests (#142) #262
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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | |
name: CI | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
test: | |
runs-on: ${{ matrix.os }}-latest | |
strategy: | |
matrix: | |
os: [ ubuntu ] | |
node-version: [18.x, 20.x, 22.x] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: pnpm/action-setup@v4 | |
with: | |
version: 'latest' | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'pnpm' | |
- run: pnpm install | |
- run: pnpm run lint:js | |
- run: pnpm run test --runInBand | |
- run: pnpm --filter '*' test | |
deploy: | |
permissions: | |
contents: write | |
deployments: write | |
needs: [ test ] | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [ 16.x ] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: pnpm/action-setup@v4 | |
with: | |
version: 'latest' | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 16.x | |
- name: pnpm install, build, | |
run: | | |
mkdir ~/.ssh | |
ssh-keyscan github.com >> ~/.ssh/known_hosts | |
pnpm install --no-audit --legacy-peer-deps | |
version=$(cat package.json | jq -r '.version') | |
git fetch --unshallow | |
git fetch --all --tags | |
TAG=v$version | |
env: | |
CI: true | |
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} | |
- name: deploy pnpm | |
if: github.ref == 'refs/heads/main' | |
run: | | |
version=$(cat package.json | jq -r '.version') | |
TAG=v$version | |
if git rev-parse "$TAG" >/dev/null 2>&1; then | |
echo "tag exists"; | |
else | |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc | |
pnpm publish || echo "already published" | |
fi | |
env: | |
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}" | |
- name: create tag | |
if: github.ref == 'refs/heads/main' | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
GITHUB_ACTOR: ${{ github.actor }} | |
GITHUB_COMMIT: ${{ github.sha }} | |
run: | | |
set -e | |
version=$(cat package.json | jq -r '.version') | |
TAG=v$version | |
if git rev-parse "$TAG" >/dev/null 2>&1; then | |
echo "tag exists"; | |
else | |
pnpm i -g lerna-changelog | |
export GITHUB_AUTH=$GITHUB_TOKEN | |
export changelog=$(lerna-changelog --next-version=$version) | |
echo -e "# Changelog\n\n$changelog\n$(tail --lines=+2 CHANGELOG.md)" > CHANGELOG.md | |
git add CHANGELOG.md | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git commit -m "update changelog" | |
git tag $TAG | |
git push | |
git push --tags | |
fi | |
- name: Create a Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
version=$(cat package.json | jq -r '.version') | |
TAG=v$version | |
url="https://api.github.com/repos/patricklx/eslint-plugin-ember-template-lint/releases" | |
exists=$(curl -H "Content-Type: application/json" -H "Authorization: token $GITHUB_TOKEN" $url | jq ".[] | select(.tag_name == \"$TAG\") | .id") | |
if [[ -z $exists ]]; then | |
curl -X POST -H "Content-Type: application/json" -H "Authorization: token $GITHUB_TOKEN" $url -d "{ \"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"$changelog\", \"draft\": false, \"prerelease\": false}" | |
else | |
echo "release already exists"; | |
fi; | |