Commit bd7cbbab authored by nanahira's avatar nanahira

finish

parent 5ffeea03
Pipeline #597 passed with stages
in 5 minutes and 21 seconds
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
/build
/output
.git*
.dockerignore
Dockerfile
.gitlab-ci.yml
/config.yaml
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
/build
/output
/config.yaml
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build:
stage: build
tags:
- docker
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
deploy_latest:
stage: deploy
tags:
- docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
deploy_tag:
stage: deploy
tags:
- docker
variables:
CONTAINER_TAG_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_TAG_IMAGE
- docker push $CONTAINER_TAG_IMAGE
only:
- tags
FROM node:buster-slim
RUN apt update && apt -y install python3 build-essential && rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/app
COPY ./package*.json ./
RUN npm ci
COPY . ./
RUN npm run build
CMD ["npm", "run", "start"]
This diff is collapsed.
template: |
战队: {{teamNames[0]}} vs {{teamNames[1]}}
时间: {{timeString}}
规则: 人头赛
地点: 679019131
------第一轮------
{% for duel of duels %}
{{duel[0].name}} ({{duel[0].qq}}) 0:0 {{duel[1].name}} ({{duel[1].qq}})
{% endfor %}
------第二轮------
matches:
- team1: AR
team2: CL
teams:
- name: AR
members:
- name: Nanahira
qq: 11111111
- name: Momobako
qq: 11111112
- name: Clala
qq: 11111113
- name: Aris
qq: 11111114
- name: Hanatan
qq: 11111115
- name: CL
members:
- name: ClariS
qq: 11111116
- name: gzzchh
qq: 11111117
- name: Meiko
qq: 11111118
- name: Yuyuko
qq: 11111119
- name: Yuyu
qq: 11111120
{
"name": "league-tabulate",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@types/node": {
"version": "14.6.0",
"resolved": "https://registry.npm.taobao.org/@types/node/download/@types/node-14.6.0.tgz?cache=0&sync_timestamp=1597674929436&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fnode%2Fdownload%2F%40types%2Fnode-14.6.0.tgz",
"integrity": "sha1-fUQRv1FXM5M318/4ZNn/RfF3tJk="
},
"@types/underscore": {
"version": "1.10.22",
"resolved": "https://registry.npm.taobao.org/@types/underscore/download/@types/underscore-1.10.22.tgz",
"integrity": "sha1-jgoTSi3wr+jaJLzwBuf5SSWj4V8="
},
"jinja-js": {
"version": "0.1.8",
"resolved": "https://registry.npm.taobao.org/jinja-js/download/jinja-js-0.1.8.tgz",
"integrity": "sha1-CxPuuW6QmT8EBRTXzmT1N4b1hRE="
},
"moment": {
"version": "2.27.0",
"resolved": "https://registry.npm.taobao.org/moment/download/moment-2.27.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fmoment%2Fdownload%2Fmoment-2.27.0.tgz",
"integrity": "sha1-i/9OPiaiNiIN/j423nVrbrqgEF0="
},
"typescript": {
"version": "4.0.2",
"resolved": "https://registry.npm.taobao.org/typescript/download/typescript-4.0.2.tgz?cache=0&sync_timestamp=1597992541174&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ftypescript%2Fdownload%2Ftypescript-4.0.2.tgz",
"integrity": "sha1-fqfIh3fHI8aB4zv3mIvl0AjQWsI="
},
"underscore": {
"version": "1.10.2",
"resolved": "https://registry.npm.taobao.org/underscore/download/underscore-1.10.2.tgz?cache=0&sync_timestamp=1585603748606&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Funderscore%2Fdownload%2Funderscore-1.10.2.tgz",
"integrity": "sha1-c9aqNmjzGI5K2w8ZQ70Sz9fvqq8="
},
"yaml": {
"version": "1.10.0",
"resolved": "https://registry.npm.taobao.org/yaml/download/yaml-1.10.0.tgz",
"integrity": "sha1-O1k63ZRIdgd9TWg/7gEIG9n/8x4="
}
}
}
{
"name": "league-tabulate",
"version": "1.0.0",
"description": "Tabulator",
"main": "build/run.js",
"scripts": {
"build": "./node_modules/.bin/tsc",
"start": "node build/run.js"
},
"repository": {
"type": "git",
"url": "git@git.mycard.moe:nanahira/league-tabulate.git"
},
"author": "Nanahira",
"license": "ISC",
"dependencies": {
"@types/node": "^14.6.0",
"@types/underscore": "^1.10.22",
"jinja-js": "^0.1.8",
"moment": "^2.27.0",
"typescript": "^4.0.2",
"underscore": "^1.10.2",
"yaml": "^1.10.0"
}
}
import fs from "fs";
import moment from "moment";
import jinja from "jinja-js";
import yaml from "yaml";
import _ from "underscore";
interface Member {
name: string;
qq: number;
}
interface Team {
name: string;
members: Member[];
}
interface Match {
team1: string;
team2: string;
}
interface Config {
template: string;
matches: Match[];
teams: Team[];
}
interface RenderData {
teamNames: string[];
timeString: string;
duels: Member[][];
}
const config: Config = yaml.parse(fs.readFileSync("./config.yaml", "utf-8"));
function shuffle(arr: any[]) {
for (let i=arr.length-1; i>=0; i--) {
let rIndex = Math.floor(Math.random()*(i+1));
let temp = arr[rIndex];
arr[rIndex] = arr[i];
arr[i] = temp;
}
return arr;
}
function makeMatch(team1: Team, team2: Team): RenderData {
if (team1.members.length !== team2.members.length) {
throw `Team ${team1.name} and ${team2.name} has different member size.`;
}
const len = team1.members.length;
const memberLists: Member[][] = ([team1, team2]).map(team => {
const list = _.clone(team.members);
shuffle(list);
return list;
});
const duels: Member[][] = [];
for (let i = 0; i < len; ++i){
duels.push([memberLists[0][i], memberLists[1][i]]);
}
return {
teamNames: [team1.name, team2.name],
timeString: moment().format("YYYY.MM.DD"),
duels
}
}
for (let match of config.matches) {
const team1 = _.find(config.teams, t => t.name === match.team1);
const team2 = _.find(config.teams, t => t.name === match.team2);
const data = makeMatch(team1, team2);
const renderedData = jinja.render(config.template, data);
console.log(renderedData);
console.log("");
}
{
"compilerOptions": {
"outDir": "build",
"module": "commonjs",
"target": "esnext",
"esModuleInterop": true,
"sourceMap": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts"
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment