Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): add gh actions #17

Merged
merged 24 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
53 changes: 53 additions & 0 deletions .github/actions/pnpm-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
########################################################################################
# "pnpm install" composite action for pnpm 7/8+ #
#--------------------------------------------------------------------------------------#
# Requirement: @setup/node should be run before #
# #
# Usage in workflows steps: #
# #
# - name: 📥 Monorepo install #
# uses: ./.github/actions/pnpm-install #
# with: #
# enable-corepack: false # (default) #
# cwd: ${{ github.workspace }}/apps/my-app # (default = '.') #
# #
# Reference: #
# - latest: https://gist.github.com/belgattitude/838b2eba30c324f1f0033a797bab2e31 #
# #
# Versions: #
# - 1.1.0 - 15-07-2023 - Add project custom directory support. #
########################################################################################

name: "PNPM install"
description: "Run pnpm install with cache enabled"

inputs:
enable-corepack:
description: "Enable corepack"
required: false
default: "false"
cwd:
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
required: false
default: "."

runs:
using: "composite"

steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: "9.4"

- name: Install dependencies
run: pnpm install
shell: bash
working-directory: ${{ inputs.cwd }}
env:
HUSKY: "0"
36 changes: 36 additions & 0 deletions .github/workflows/clean_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: Cleanup caches for closed branches

on:
pull_request:
types:
- closed
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache

REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"

echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )

## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "CodeQL"

on:
schedule:
- cron: "30 1 * * *"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

permissions:
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
113 changes: 113 additions & 0 deletions .github/workflows/webiste.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webiste typo

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Website

on:
push:
paths: ["src/**", ".github/workflows/website.yml"]

pull_request:
paths: ["src/**", ".github/workflows/website.yml"]

env:
NODE_VERSION: "21"
CONTAINER_REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
conflicts:
runs-on: ubuntu-latest
steps:
- name: Check for PR conflicts
uses: eps1lon/actions-label-merge-conflict@releases/2.x
with:
dirtyLabel: "has conflicts"
repoToken: "${{ secrets.GITHUB_TOKEN }}"

analyze:
name: Analyze
runs-on: ubuntu-latest

permissions:
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

es-lint:
name: Check linting (es-lint)
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: PNPM Install
uses: ./.github/actions/pnpm-install

- name: Check ESlint
run: pnpm lint

prettier:
name: Check formatting (prettier)
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: PNPM Install
uses: ./.github/actions/pnpm-install

- name: Check Prettier
run: pnpm prettier --check .

sveltecheck:
name: Svelte Check
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: PNPM Install
uses: ./.github/actions/pnpm-install

- name: Make dummy env for types
run: |
echo "ls -a ."
ls -a .
mv .env.example .env

- name: Check Svelte
run: pnpm run check

build:
name: Svelte Build
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Clone NotEnoughUpdates-REPO
uses: actions/checkout@v3
with:
repository: NotEnoughUpdates/NotEnoughUpdates-REPO
path: src/lib/constants/NotEnoughUpdates-REPO/items
token: ${{ secrets.GITHUB_TOKEN }}

- name: PNPM Install
uses: ./.github/actions/pnpm-install

- name: Make dummy env for types
run: |
echo "ls -a ."
ls -a .
mv .env.example .env

- name: Svelte Build
run: pnpm run build
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ $RECYCLE.BIN/

build/
package/
cache/
cache/head/*
cache/json/*.json
cache/leather/*
cache/potion/*
node_modules/
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
Expand Down
Empty file added cache/json/.gitkeep
Empty file.
6 changes: 3 additions & 3 deletions src/lib/components/Item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Avatar, Tooltip } from "bits-ui";
import Image from "lucide-svelte/icons/image";

export let piece: ProcessedItem;
export let piece: ProcessedItem | ProcessedPet;
export let isInventory = false;
export let showCount = true;

Expand All @@ -16,7 +16,7 @@
const bgColor = piece.rarity ? getRarityClass(piece.rarity.toLowerCase() as string, "bg") : "bg-background";
const enchanted = isEnchanted(piece as ProcessedItem);

const showNumbers = showCount && piece.Count > 1;
const showNumbers = showCount && (piece as ProcessedItem).Count > 1;
DuckySoLucky marked this conversation as resolved.
Show resolved Hide resolved

const processedItem = piece as ProcessedItem;
const processedPet = piece as unknown as ProcessedPet;
Expand All @@ -33,7 +33,7 @@
</Avatar.Root>
{#if showNumbers}
<div class="absolute bottom-0.5 right-0.5 text-2xl font-semibold text-white text-shadow-[.1em_.1em_.1em_#000]">
{piece.Count}
{processedItem.Count}
</div>
{/if}
</Tooltip.Trigger>
Expand Down
3 changes: 3 additions & 0 deletions src/lib/scripts/parseNEURepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const NEU_CONSTANTS = new Map();

export async function parseNEURepository() {
const timeNow = performance.now();
if (fs.statSync("src/lib/constants/NotEnoughUpdates-REPO/items").isDirectory()) {
return;
}

const items = fs.readdirSync("src/lib/constants/NotEnoughUpdates-REPO/items");
for (const item of items) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/sections/stats/Accessories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@
<span style="color: var(--§6)"> +{accessories.magicalPower.riftPrism} MP</span>
</li>
{/if}
{#if accessories.magicalPower.hegemony > 0}
{#if accessories.magicalPower.hegemony.amount > 0 && accessories.magicalPower.hegemony.rarity !== null}
DuckySoLucky marked this conversation as resolved.
Show resolved Hide resolved
<li>
<span style="color: var(--§{RARITY_COLORS[accessories.magicalPower.rarities.hegemony.rarity]}">Hegemony Artifact: </span>
<span style="color: var(--§{RARITY_COLORS[accessories.magicalPower.hegemony.rarity]}">Hegemony Artifact: </span>
=
<span style="color: var(--§6)"> +{accessories.magicalPower.hegemony} MP</span>
</li>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/sections/stats/Inventory.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
});
</script>

<Tabs.Root bind:value={$openTab} class="@container relative mb-0 rounded-lg bg-background/30 p-5">
<Tabs.Root bind:value={$openTab} class="relative mb-0 rounded-lg bg-background/30 p-5 @container">
<Tabs.List class="flex items-center gap-3 border-b border-icon px-4">
{#each tabs as tab}
{@const isActive = $openTab === tab.id}
Expand All @@ -101,7 +101,7 @@
{#each tabs as tab}
<Tabs.Content value={tab.id} asChild let:builder>
{#if $openTab === tab.id}
<div use:builder.action {...builder} class="@md:gap-1.5 @xl:gap-2 grid grid-cols-[repeat(9,minmax(1.875rem,4.875rem))] place-content-center gap-1 pt-5">
<div use:builder.action {...builder} class="grid grid-cols-[repeat(9,minmax(1.875rem,4.875rem))] place-content-center gap-1 pt-5 @md:gap-1.5 @xl:gap-2">
{#each tab.items as item, index}
{#if tab.hr === index}
<hr class="col-start-1 col-end-10 h-4 border-0" />
Expand Down
5 changes: 2 additions & 3 deletions src/lib/stats/items/stats.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getRawLore } from "$lib/helper";
import type { ProcessedItem } from "$types/stats";
import * as constants from "$constants/constants";
import { getRawLore } from "$lib/helper";
import type { ItemStats } from "$types/processed/profile/stats";
import type { ProcessedItem } from "$types/stats";

export function getStatsFromItem(item: ProcessedItem) {
const regex = /^([A-Za-z ]+): ([+-]([0-9]+(?:,[0-9]{3})*(?:\.[0-9]{0,2})?))/;
Expand All @@ -25,7 +25,6 @@ export function getStatsFromItem(item: ProcessedItem) {
if (statName) {
stats[statName] = 0;

// @ts-expect-error: Object is possibly 'null'.
stats[statName] += statValue;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/stats/missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export async function getMissingAccessories(items: Accessories, userProfile: Mem
accessories: activeAccessories.reduce((a, b) => a + helper.getMagicalPower(b.rarity, helper.getId(b)), 0),
abiphone: abiphoneContacts ? Math.floor(abiphoneContacts / 2) : 0,
riftPrism: riftPrism ? 11 : 0,
hegemony: {
rarity: activeAccessories.find((a) => helper.getId(a) === "HEGEMONY")?.rarity ?? null,
amount: helper.getMagicalPower(activeAccessories.find((a) => helper.getId(a) === "HEGEMONY")?.rarity ?? "", "HEGEMONY_ARTIFACT")
},
rarities: {}
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/stats/player_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function getPlayerStats(profile: Stats) {
}
}

if (profile.slayer.data) {
if (profile.slayer?.data) {
for (const [slayer, data] of Object.entries(profile.slayer.data)) {
const bonusStats = getBonusStat(data.level.level, `slayer_${slayer}`, data.level.maxLevel);

Expand All @@ -106,7 +106,7 @@ export function getPlayerStats(profile: Stats) {
}
}

if (profile.dungeons.level.level > 0) {
if (profile.dungeons?.level?.level !== undefined) {
DuckySoLucky marked this conversation as resolved.
Show resolved Hide resolved
const bonusStats = getBonusStat(profile.dungeons.level.level, "skill_dungeoneering", 50);

for (const [name, value] of Object.entries(bonusStats)) {
Expand Down
5 changes: 2 additions & 3 deletions src/lib/stats/slayer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Member, SlayerBoss } from "$types/global";
import * as constants from "$constants/constants";
import type { Slayer } from "$types/processed/profile/slayer";
import type { Member, SlayerBoss, SlayerData } from "$types/global";

function getKills(slayer: SlayerBoss) {
if (slayer === undefined) {
Expand Down Expand Up @@ -64,7 +63,7 @@ export function getSlayer(userProfile: Member) {
return null;
}

const output = { data: {} } as Slayer;
const output = { data: {} } as SlayerData;
for (const id of constants.SLAYERS) {
const data = slayerData[id];
output.data[id] = {
Expand Down
4 changes: 4 additions & 0 deletions src/types/processed/profile/items.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ export type AccessoriesOutput = {
accessories: number;
abiphone: number;
riftPrism: number;
hegemony: {
rarity: string | null;
amount: number;
};
rarities: Record<string, { amount: number; magicalPower: number }>;
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/types/stats.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type Stats = {
mining: MiningStats;
farming: Farming;
fishing: Fishing;
slayer: SlayerData;
slayer: SlayerData | null;
dungeons: DungeonsStats | null;
minions: Minions;
bestiary: BestiaryStats;
Expand Down
Loading
Loading