Skip to content

Commit

Permalink
Merge pull request #144 from NMSCD/dev
Browse files Browse the repository at this point in the history
Update to WorldsOne
  • Loading branch information
Lenni009 authored Aug 11, 2024
2 parents ffb16c5 + 70b1c0b commit 74c46de
Show file tree
Hide file tree
Showing 23 changed files with 4,893 additions and 870 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ updates:
target-branch: 'dev'
schedule:
interval: 'weekly'
groups:
vitest:
patterns:
- '*vitest*'

- package-ecosystem: 'github-actions'
directory: '/'
Expand Down
86 changes: 0 additions & 86 deletions .github/workflows/build-deploy.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/check-pr-branch.yml

This file was deleted.

124 changes: 124 additions & 0 deletions .github/workflows/deploy-all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Build

run-name: Build Code

on:
push:
branches: ['main']

permissions:
contents: write

concurrency:
group: 'build-deploy'
cancel-in-progress: true

# You should only need to touch these two variables
env:
buildCommand: |
npm ci
npm run build
buildOutput: dist # optionally "dist" if build step is needed

jobs:
build-main:
environment: github-pages
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Build App
run: ${{ env.buildCommand }}

- name: Minify Code
uses: Lenni009/minify-js@main
with:
directory: ${{ env.buildOutput }}
overwrite: true

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: main
path: ${{ env.buildOutput }}

getPRs:
runs-on: ubuntu-latest

outputs:
prData: ${{ steps.data.outputs.pullRequestData }}

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1

- name: Get PR Data
id: data
run: |
data=$(deno run --allow-net .github/workflows/getPRs.ts ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }}) # output: pullRequestData: {ref: string, number: number}[]
echo "pullRequestData=$data" >> "$GITHUB_OUTPUT"
build-pr:
runs-on: ubuntu-latest
needs: getPRs
# GH Actions outputs are strings, so we can just compare this to an empty array string. `.length` does not seem to work when parsing the array.
if: needs.getPRs.outputs.prData != '[]'

strategy:
matrix:
data: ${{ fromJSON(needs.getPRs.outputs.prData) }}

steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ matrix.data.ref }}

- name: Add Base Path to Vite Config
run: echo 'VITE_BASE_PATH=/pr/${{ matrix.data.number }}/' > .env

- name: Build App
run: ${{ env.buildCommand }}

- name: Minify Code
uses: Lenni009/minify-js@main
with:
directory: ${{ env.buildOutput }}
overwrite: true

- name: Upload App
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.data.number }}
path: ${{ env.buildOutput }}

deploy:
runs-on: ubuntu-latest
if: ${{ !cancelled() && !failure() }}
needs: ['build-main', 'build-pr']

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Download App
uses: actions/download-artifact@v4
with:
path: dist/pr

- name: Move Main Deployment
run: |
cd dist
cp -r pr/main/* .
rm -rf pr/main
touch .nojekyll
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist
47 changes: 47 additions & 0 deletions .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy PR

run-name: Deploy PR

on:
pull_request:
types: ["opened", "synchronize"]
branches: ["main"]

permissions:
contents: write
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Build App
run: |
echo 'VITE_BASE_PATH=/pr/${{ github.event.number }}/' > .env
npm ci
npm run build
- name: Minify Code
uses: Lenni009/minify-js@main
with:
directory: dist
overwrite: true

- name: Get GH Pages URL
id: pages
uses: actions/configure-pages@v5

- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist
target-folder: "pr/${{ github.event.number }}" # The folder the action should deploy to.

- name: Add PR Comment
uses: mshick/add-pr-comment@v2
with:
message: "Deployed to ${{ steps.pages.outputs.base_url }}/pr/${{ github.event.number }}/"
37 changes: 37 additions & 0 deletions .github/workflows/getPRs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import core from 'npm:@actions/core';
import github from 'npm:@actions/github';
import { RestEndpointMethodTypes } from 'npm:@octokit/plugin-rest-endpoint-methods';

type PRListResponse = RestEndpointMethodTypes['pulls']['list']['response'];

async function listPullRequests(token: string, repoOwner: string, repo: string, state: 'open' | 'closed' | 'all') {
const octokit = github.getOctokit(token);
const pullRequests = await octokit.rest.pulls.list({
repo,
state,
owner: repoOwner,
sort: 'created',
direction: 'desc',
per_page: 100,
});
return pullRequests;
}

function outputRefs(list: PRListResponse) {
const prDataList = list.data.map((p) => ({
ref: p.head.ref,
number: p.number,
}));
console.log(prDataList);
}

try {
const [repoData, token] = Deno.args;
const [repoOwner, repo] = repoData.split('/');
const state = 'open';

const list = await listPullRequests(token, repoOwner, repo, state);
outputRefs(list);
} catch (error) {
core.setFailed(error.message);
}
4 changes: 0 additions & 4 deletions .github/workflows/lintdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ on:
pull_request:
types: [opened, synchronize]

concurrency:
group: "lintdoc"
cancel-in-progress: true

jobs:
Lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ on:
pull_request:
types: [opened, synchronize]

concurrency:
group: "testbuild"
cancel-in-progress: true

jobs:
Build:
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions moon.html
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,7 @@ <h1 class="title is-3">NMS Wiki Page Creator - Moon</h1>

<div>==Life==</div>
<div>===Fauna===</div>
<div>* There <output id="faunaSentencePlural"></output> <output id="faunaNumberSentence"
name="faunaNumber"></output> fauna on this moon</div>
<div>* There <output id="faunaNumberSentence"></output> on this moon</div>
<div>{| class="article-table" style="text-align:center; width:100%; max-width: 1250px"</div>
<div>|-</div>
<div>! style="width:150px" | Image</div>
Expand Down
Loading

0 comments on commit 74c46de

Please sign in to comment.