Skip to content

Commit

Permalink
Create node.js.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed May 4, 2024
1 parent 73507ff commit da3e6fd
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 71 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build
on:
push:
branches: main
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: write
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
- uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'npm'
- name: Install dependencies
run: npm ci --force
- name: Lint and fix errors
run: npm run lint:fix
- name: Format code
run: npm run format:fix
- name: Build package
run: npm run build
- name: Commit changes
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
git add -A
if ! git diff --cached --exit-code; then
git commit -m "Code maintenance: bump version, lint and format"
if [[ ${{ github.ref }} == "refs/heads/main" ]]; then
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
BRANCH_NAME="maintenance-$(date +'%Y%m%d%H%M%S')"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
gh pr create --base main --head "$BRANCH_NAME" --title "Maintenance PR" --body "Automatic code maintenance: bump version, lint and format."
gh pr merge --auto --squash --delete-branch ${{ github.event.pull_request.html_url }}
else
git pull origin ${{ github.head_ref }} --rebase
git push origin HEAD:${{ github.head_ref }}
fi
else
echo "No changes to commit."
fi
23 changes: 23 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Dependabot auto-merge
on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Enable auto-merge for Dependabot PRs
if: contains(steps.metadata.outputs.dependency-names, 'my-dependency') && steps.metadata.outputs.update-type == 'version-update:semver-patch'
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish package to GitHub Packages
on:
release:
types: [published]

permissions:
contents: read
packages: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@olivierzal'
- run: npm ci --force
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.npmrc
/.vscode/*
!/.vscode/settings.json
/coverage/
Expand Down
82 changes: 41 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "ariston-api",
"name": "@olivierzal/ariston-api",
"version": "1.0.0",
"description": "Ariston API package for NodeJS",
"description": "Ariston API for NodeJS",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/OlivierZal/ariston-api.git"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"keywords": [
"ariston",
"api"
Expand All @@ -33,11 +36,11 @@
"prepare": "npm run build"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^1.7.2",
"@stylistic/eslint-plugin": "^1.8.0",
"@types/luxon": "^3.4.2",
"@types/node": "^20.12.7",
"@types/node": "^20.12.8",
"@types/tough-cookie": "^4.0.5",
"eslint": "^9.1.1",
"eslint": "^9.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
Expand Down
14 changes: 6 additions & 8 deletions src/lib/APICallErrorData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type APICallContextData from './APICallContextData'
import APICallRequestData from './APICallRequestData'
import APICallResponseData from './APICallResponseData'
import {
type APICallContextData,
APICallRequestData,
APICallResponseData,
} from '..'
import type { AxiosError } from 'axios'

interface APICallContextDataWithErrorMessage extends APICallContextData {
Expand All @@ -17,11 +19,7 @@ const withErrorMessage = <T extends new (...args: any[]) => APICallContextData>(
public readonly errorMessage = error.message
}

const createAPICallErrorData = (
error: AxiosError,
): APICallContextDataWithErrorMessage =>
export default (error: AxiosError): APICallContextDataWithErrorMessage =>
typeof error.response === 'undefined' ?
new (withErrorMessage(APICallRequestData, error))(error.config)
: new (withErrorMessage(APICallResponseData, error))(error.response)

export default createAPICallErrorData
2 changes: 1 addition & 1 deletion src/lib/APICallRequestData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import APICallContextData from './APICallContextData'
import { APICallContextData } from '..'
import type { InternalAxiosRequestConfig } from 'axios'

export default class APICallRequestData extends APICallContextData {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/APICallResponseData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AxiosResponse, InternalAxiosRequestConfig } from 'axios'
import APICallContextData from './APICallContextData'
import { APICallContextData } from '..'

export default class APICallResponseData extends APICallContextData {
public readonly headers?: AxiosResponse['headers']
Expand Down
30 changes: 15 additions & 15 deletions src/lib/AristonAPI.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import {
APICallRequestData,
APICallResponseData,
type GetData,
type GetSettings,
type LoginCredentials,
type LoginData,
type LoginPostData,
type Plant,
type PostData,
type PostSettings,
type ReportData,
createAPICallErrorData,
} from '..'
import { DateTime, Duration } from 'luxon'
import type {
GetData,
GetSettings,
LoginCredentials,
LoginData,
LoginPostData,
Plant,
PostData,
PostSettings,
ReportData,
} from '../types'
import axios, {
type AxiosError,
type AxiosInstance,
type AxiosResponse,
type InternalAxiosRequestConfig,
} from 'axios'
import APICallRequestData from './APICallRequestData'
import APICallResponseData from './APICallResponseData'
import { CookieJar } from 'tough-cookie'
import createAPICallErrorData from './APICallErrorData'
import { wrapper } from 'axios-cookiejar-support'

interface APISettings {
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class AristonAPI {
}

public async applyLogin(data?: LoginCredentials): Promise<boolean> {
const { password, username } = data ?? {
const { username, password } = data ?? {
password: this.#settingManager.get('password') ?? '',
username: this.#settingManager.get('username') ?? '',
}
Expand Down

0 comments on commit da3e6fd

Please sign in to comment.