Compare commits
13 Commits
8d3b63440a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b19ba0ba1f | |||
| a67b120cf4 | |||
| 634b99dfff | |||
| 2d124df653 | |||
| 89ea0d02d9 | |||
| dba950724e | |||
| 9235077f0a | |||
| efad238257 | |||
| 0dd5fbef0f | |||
| 0b5a1e7cd3 | |||
| 7589710e2a | |||
| d754dbe836 | |||
| 524d9d4a6e |
@@ -1,9 +1,9 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/alpine
|
||||
{
|
||||
"name": "Alpine",
|
||||
"name": "KamishiroUPM",
|
||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||
"image": "mcr.microsoft.com/devcontainers/base:alpine-3.20",
|
||||
"image": "mcr.microsoft.com/devcontainers/base:alpine",
|
||||
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
//"features": { }
|
||||
@@ -12,10 +12,20 @@
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "uname -a",
|
||||
"onCreateCommand": "sudo /bin/sh .devcontainer/initialize.sh",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
// "customizations": {},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"foxundermoon.shell-format",
|
||||
"GitLab.gitlab-workflow",
|
||||
"golang.go",
|
||||
"redhat.vscode-yaml",
|
||||
"streetsidesoftware.code-spell-checker"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "root"
|
||||
|
||||
9
.devcontainer/initialize.sh
Normal file
9
.devcontainer/initialize.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
apk add git git-lfs npm go
|
||||
|
||||
git config --global http.sslVerify false
|
||||
git config --global advice.detachedHead false
|
||||
|
||||
go mod init KamishiroUPM
|
||||
go get github.com/joho/godotenv
|
||||
go get github.com/google/uuid
|
||||
go mod tidy
|
||||
11
.gitattributes
vendored
11
.gitattributes
vendored
@@ -1,5 +1,10 @@
|
||||
*.gitattributes text eol=lf
|
||||
*.gitignore text eol=lf
|
||||
*.go* text eol=lf
|
||||
*.json text eol=lf
|
||||
*.sh text eol=lf
|
||||
*.yml text eol=lf
|
||||
*.md text eol=lf
|
||||
*.git* text eol=lf
|
||||
*.mod text eol=lf
|
||||
*.sh text eol=lf
|
||||
*.sum text eol=lf
|
||||
*.yml text eol=lf
|
||||
License text eol=lf
|
||||
|
||||
33
.github/workflows/release.yml
vendored
Normal file
33
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
env:
|
||||
NPM_USER: ${{ secrets.NPM_USER }}
|
||||
NPM_PASS: ${{ secrets.NPM_PASS }}
|
||||
NPM_REGISTRY: ${{ vars.NPM_REGISTRY }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: win-x64
|
||||
|
||||
container:
|
||||
image: alpine:latest
|
||||
|
||||
steps:
|
||||
- name: Add packages
|
||||
run: apk add git nodejs
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run Go release script
|
||||
run: |
|
||||
chmod +x ./.devcontainer/initialize.sh
|
||||
./.devcontainer/initialize.sh
|
||||
go run ./release.go
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,5 +1,2 @@
|
||||
!repos
|
||||
!package.sh
|
||||
!README.md
|
||||
!.gitlab-ci.yml
|
||||
!.gitignore
|
||||
.env
|
||||
_target_*
|
||||
@@ -1,21 +0,0 @@
|
||||
stages:
|
||||
- deploy
|
||||
|
||||
.build: &build
|
||||
image: alpine:latest
|
||||
stage: deploy
|
||||
script:
|
||||
- chmod +x ./package.sh && ./package.sh
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
|
||||
detect-change:
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "main"'
|
||||
<<: *build
|
||||
|
||||
timer:
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "schedule"
|
||||
when: manual
|
||||
<<: *build
|
||||
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
@@ -1,3 +1,10 @@
|
||||
{
|
||||
"python.analysis.typeCheckingMode": "basic"
|
||||
"cSpell.words": [
|
||||
"devcontainer",
|
||||
"devcontainers",
|
||||
"foxundermoon",
|
||||
"godotenv",
|
||||
"joho",
|
||||
"Kamishiro"
|
||||
]
|
||||
}
|
||||
7
License
Normal file
7
License
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright 2023 AoiKamishiro
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
106
README.md
106
README.md
@@ -1,92 +1,22 @@
|
||||
# KamishiroUPM
|
||||
|
||||
UnityPackage用リポジトリサーバーへ、最新のパッケージ登録を自動的に行うリポジトリです。
|
||||
Unityプロジェクトへ <https://package.kamishiro.online/> を追加する事で、PackageManagerから利用可能になります。
|
||||
|
||||
## 対応済みパッケージ一覧
|
||||
|
||||
## Getting started
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.kamishiro.online/aoikamishiro/kamishiroupm.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.kamishiro.online/aoikamishiro/kamishiroupm/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
- [uPools](https://github.com/AnnulusGames/uPools)
|
||||
- [SubAssetEditor](https://github.com/AoiKamishiro/SubAssetEditor)
|
||||
- [R3](https://github.com/Cysharp/R3)
|
||||
- [UniTask](https://github.com/Cysharp/UniTask)
|
||||
- [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity)
|
||||
- [xNode](https://github.com/siccity/xNode)
|
||||
- [uLipSync](https://github.com/hecomi/uLipSync)
|
||||
- [Extenject](https://github.com/Mathijs-Bakker/Extenject)
|
||||
- [Pun2Task](https://github.com/TORISOUP/Pun2Task)
|
||||
- [UniVRM](https://github.com/vrm-c/UniVRM)
|
||||
- [unity-universal-shadergraph-extensions](https://github.com/Zallist/unity-universal-shadergraph-extensions)
|
||||
- [VContainer](https://github.com/hadashiA/VContainer)
|
||||
- [ExternalToolsLauncher](https://github.com/AoiKamishiro/ExternalToolsLauncher)
|
||||
- [Readme-Viewer](https://github.com/AoiKamishiro/Readme-Viewer)
|
||||
- [CopyComponentsByRegex](https://github.com/Taremin/CopyComponentsByRegex)
|
||||
|
||||
8
go.mod
Normal file
8
go.mod
Normal file
@@ -0,0 +1,8 @@
|
||||
module KamishiroUPM
|
||||
|
||||
go 1.22.6
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
)
|
||||
4
go.sum
Normal file
4
go.sum
Normal file
@@ -0,0 +1,4 @@
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
131
package.sh
131
package.sh
@@ -1,131 +0,0 @@
|
||||
apk add curl git git-lfs icu-data-full jq npm uuidgen sed >/dev/null
|
||||
git config --global http.sslVerify false
|
||||
git config --global advice.detachedHead false
|
||||
|
||||
Repo_Process() {
|
||||
# Prepare Variables
|
||||
local UUID=$(uuidgen)
|
||||
local WORK_ROOT=$1
|
||||
local REPO_SETTING=$2
|
||||
local ADDR=$(echo $REPO_SETTING | jq -r '.addr')
|
||||
local DIR=$(echo $REPO_SETTING | jq -r '.dir')
|
||||
local TAG_REGEX=$(echo $REPO_SETTING | jq -r '.tagRegex')
|
||||
local IGNORE_REPO=$(echo $REPO_SETTING | jq -r '.ignore')
|
||||
|
||||
local REPO_NAME=$(basename $ADDR | sed 's/\.[^\.]*$//')
|
||||
local AUTHOR_NAME=$(echo "$ADDR" | awk -F[/:] '{print $(NF-1)}')
|
||||
local PACKAGE_NAME=$(basename $DIR)
|
||||
|
||||
local PACKAGE_ROOT="$WORK_ROOT/$REPO_NAME-$UUID"
|
||||
local PACKAGE_DIR="$WORK_ROOT/$REPO_NAME-$UUID/$DIR"
|
||||
|
||||
# Check if ignore
|
||||
if [[ "$IGNORE_REPO" == "true" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$TAG_REGEX" == null ]]; then
|
||||
local TAG_REGEX="^[0-9]+\.[0-9]+\.[0-9]+$"
|
||||
fi
|
||||
|
||||
if [[ "$DIR" == null ]]; then
|
||||
local DIR="."
|
||||
fi
|
||||
|
||||
# Download latest version
|
||||
cd $WORK_ROOT
|
||||
git clone $ADDR $REPO_NAME-$UUID >/dev/null 2>&1
|
||||
cd $PACKAGE_ROOT
|
||||
|
||||
local TAGS=$(git tag -l --sort authordate)
|
||||
|
||||
# Tag Process
|
||||
for TAG in $TAGS; do
|
||||
|
||||
# Check if tag is valid
|
||||
if [[ ! $TAG =~ $TAG_REGEX ]]; then
|
||||
echo "$REPO_NAME:$DIR@$TAG is invalid tag."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Prepare Variables
|
||||
local GITHUB_PACKAGE_ADDR="https://raw.githubusercontent.com/${AUTHOR_NAME}/${REPO_NAME}/${TAG}/${DIR}/package.json"
|
||||
|
||||
# 404 Check
|
||||
local GITHUB_STAT=$(curl -sL $GITHUB_PACKAGE_ADDR -o /dev/null -w '%{http_code}\n')
|
||||
if [[ "$GITHUB_STAT" != "200" ]]; then
|
||||
echo "$REPO_NAME:$DIR@$TAG has invalid path."
|
||||
continue
|
||||
fi
|
||||
|
||||
local PACKAGE_JSON=$(curl -sL $GITHUB_PACKAGE_ADDR)
|
||||
local GITHUB_NAME=$(echo "$PACKAGE_JSON" | jq -r .name)
|
||||
local SEM_VERSION=$(echo "$TAG" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
|
||||
|
||||
# Get Server tag
|
||||
local SVR_STAT=$(curl -sL https://$NPM_REGISTRY/$GITHUB_NAME -o /dev/null -w '%{http_code}\n')
|
||||
local SVR_VERS=""
|
||||
if [[ "$SVR_STAT" == "200" ]]; then
|
||||
local SVR_DATA=$(curl -sL https://$NPM_REGISTRY/$GITHUB_NAME)
|
||||
local SVR_VERS=$(echo $SVR_DATA | jq .versions | jq -s -r '[ .[] | keys ] | flatten | unique | .[]')
|
||||
fi
|
||||
|
||||
# Check server version
|
||||
local EXIST_ON_SVR="false"
|
||||
for SVR_VER in $SVR_VERS; do
|
||||
if [[ "$SVR_VER" == "$SEM_VERSION" ]]; then
|
||||
local EXIST_ON_SVR="true"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ "$EXIST_ON_SVR" == "true" ]]; then
|
||||
echo "$REPO_NAME:$DIR@$TAG is already published."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Download Repository
|
||||
cd $WORK_ROOT
|
||||
rm -r $PACKAGE_ROOT
|
||||
git clone -b $TAG $ADDR $REPO_NAME-$UUID >/dev/null 2>&1
|
||||
cd $PACKAGE_ROOT
|
||||
git submodule update --init --recursive >/dev/null 2>&1
|
||||
git lfs pull >/dev/null 2>&1
|
||||
|
||||
cd $PACKAGE_DIR
|
||||
|
||||
# Change Version
|
||||
local PROCESS_VER='.version="'$SEM_VERSION'"'
|
||||
local PACKAGE_JSON=$(echo "$PACKAGE_JSON" | jq "$PROCESS_VER" | jq -c .)
|
||||
|
||||
# Update package.json
|
||||
rm package.json
|
||||
echo $PACKAGE_JSON >package.json
|
||||
|
||||
# Publish Package
|
||||
local DATA='{"name":"'"$NPM_USER"'", "password":"'"$NPM_PASS"'"}'
|
||||
local USER="$NPM_USER":"$NPM_PASS"
|
||||
local RETURN=$(curl -sL -H "Accept:application/json" -H "Content-Type:application/json" -X PUT --data "$DATA" --user "$USER" https://$NPM_REGISTRY/-/user/org.couchdb.user:$NPM_USER)
|
||||
local TOKEN=$(echo $RETURN | jq '.token')
|
||||
npm set //$NPM_REGISTRY/:_authToken $TOKEN
|
||||
npm publish --registry https://$NPM_REGISTRY/ >/dev/null 2>&1
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "$REPO_NAME:$DIR@$TAG failed to publish."
|
||||
else
|
||||
echo "$REPO_NAME:$DIR@$TAG published."
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
cd $WORK_ROOT
|
||||
rm -r $PACKAGE_ROOT
|
||||
}
|
||||
|
||||
JSON_FILES=$(find ./repos -name "*.json")
|
||||
for JSON_FILE in $JSON_FILES; do
|
||||
ROOT=$(pwd)
|
||||
OBJ=$(cat $JSON_FILE | jq -c .)
|
||||
Repo_Process "$ROOT" "$OBJ" &
|
||||
done
|
||||
|
||||
wait
|
||||
409
release.go
Normal file
409
release.go
Normal file
@@ -0,0 +1,409 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type RepoType int
|
||||
|
||||
const (
|
||||
Unknown RepoType = iota
|
||||
GitHub
|
||||
GitLab
|
||||
BitBucket
|
||||
)
|
||||
|
||||
type RepoSetting struct {
|
||||
Addr string `json:"addr"`
|
||||
Dir string `json:"dir"`
|
||||
TagRegex string `json:"tagRegex"`
|
||||
Ignore string `json:"ignore"`
|
||||
}
|
||||
|
||||
// RepoType と ドメインのマッピング
|
||||
var repoTypeMap = map[RepoType]string{
|
||||
GitHub: "https://raw.githubusercontent.com",
|
||||
}
|
||||
|
||||
func main() {
|
||||
godotenv.Load(".env")
|
||||
npmUser := os.Getenv("NPM_USER")
|
||||
npmPass := os.Getenv("NPM_PASS")
|
||||
npmRegistry := os.Getenv("NPM_REGISTRY")
|
||||
isDevMode := os.Getenv("DEV_MODE") == "true"
|
||||
|
||||
jsonFiles, _ := filepath.Glob("./repos/*.json")
|
||||
|
||||
token, err := getNpmAuthToken(npmRegistry, npmUser, npmPass)
|
||||
if err != nil {
|
||||
fmt.Printf("[Error] NPM Auth Failed. %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for _, jsonFile := range jsonFiles {
|
||||
root, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Printf("[Error] Root Directory Get Failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
fileContent, err := os.ReadFile(jsonFile)
|
||||
if err != nil {
|
||||
fmt.Printf("[Error] File Read Failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
var repoSetting RepoSetting
|
||||
if err := json.Unmarshal(fileContent, &repoSetting); err != nil {
|
||||
fmt.Printf("[Error] JSON Parse Failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go processRepository(root, repoSetting, token, npmRegistry, &wg, isDevMode)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func processRepository(workRoot string, repoSetting RepoSetting, npmToken, npmRegistry string, wg *sync.WaitGroup, devMode bool) {
|
||||
defer wg.Done()
|
||||
|
||||
// 変数の準備
|
||||
uuid := uuid.New().String()
|
||||
addr := repoSetting.Addr
|
||||
dir := repoSetting.Dir
|
||||
tagRegex := repoSetting.TagRegex
|
||||
ignore := repoSetting.Ignore == "true"
|
||||
|
||||
repositoryName := strings.TrimSuffix(filepath.Base(addr), filepath.Ext(addr))
|
||||
repositoryAuthor := strings.Split(addr, "/")[len(strings.Split(addr, "/"))-2]
|
||||
|
||||
repositoryDirName := fmt.Sprintf("_target_%s-%s", repositoryName, uuid)
|
||||
repositoryRoot := filepath.Join(workRoot, repositoryDirName)
|
||||
packageRoot := filepath.Join(repositoryRoot, dir)
|
||||
|
||||
var npmVersions map[string][]string = make(map[string][]string)
|
||||
|
||||
var repositoryType RepoType = Unknown
|
||||
if strings.HasPrefix(addr, "https://github.com/") {
|
||||
repositoryType = GitHub
|
||||
}
|
||||
|
||||
if tagRegex == "" {
|
||||
tagRegex = "^[0-9]+\\.[0-9]+\\.[0-9]+$"
|
||||
}
|
||||
|
||||
if dir == "" {
|
||||
dir = "."
|
||||
}
|
||||
|
||||
if ignore {
|
||||
fmt.Printf("[Info] Ignored. %s:%s\n", repositoryName, dir)
|
||||
return
|
||||
}
|
||||
|
||||
// Tagの確認
|
||||
remoteTags, err := getRemoteTags(addr)
|
||||
if err != nil {
|
||||
fmt.Printf("[Error] Invalid Repository. %s\n", addr)
|
||||
return
|
||||
}
|
||||
|
||||
var validTags []string
|
||||
|
||||
// 有効なTagのみを抽出
|
||||
for _, tag := range remoteTags {
|
||||
matched, _ := regexp.MatchString(tagRegex, tag)
|
||||
if !matched {
|
||||
fmt.Printf("[Warn] Invalid Tag. %s:%s@%s\n", repositoryName, dir, tag)
|
||||
} else {
|
||||
validTags = append(validTags, tag)
|
||||
}
|
||||
}
|
||||
|
||||
var unpublishedTags []string
|
||||
tagChan := make(chan string)
|
||||
|
||||
// 非同期に未アップロードのタグを抽出
|
||||
for _, tag := range validTags {
|
||||
go func(tag string) {
|
||||
repositoryJSON, err := getPackageJson(repositoryType, repositoryAuthor, repositoryName, tag, dir)
|
||||
if err != nil {
|
||||
fmt.Printf("[Warn] Invalid Path. %s:%s@%s\n", repositoryName, dir, tag)
|
||||
tagChan <- ""
|
||||
return
|
||||
}
|
||||
|
||||
packageName := repositoryJSON["name"].(string)
|
||||
packageVersion := regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9]+`).FindString(tag)
|
||||
|
||||
if npmVersions[packageName] == nil {
|
||||
npmVersions[packageName], err = getNpmTags("https://"+npmRegistry, packageName)
|
||||
if err != nil {
|
||||
fmt.Printf("[Warn] Invalid Repository. %s\n", err)
|
||||
// 未アップロードなだけなのでエラーとしない
|
||||
}
|
||||
}
|
||||
|
||||
// サーバーに存在するか確認
|
||||
existOnServer := false
|
||||
for _, npmVersion := range npmVersions[packageName] {
|
||||
if npmVersion == packageVersion {
|
||||
existOnServer = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if existOnServer {
|
||||
fmt.Printf("[Info] Already Published. %s:%s@%s\n", repositoryName, dir, tag)
|
||||
tagChan <- ""
|
||||
} else {
|
||||
tagChan <- tag
|
||||
}
|
||||
}(tag)
|
||||
}
|
||||
|
||||
// チャネルから結果を受け取る
|
||||
for range validTags {
|
||||
tag := <-tagChan
|
||||
if tag != "" {
|
||||
unpublishedTags = append(unpublishedTags, tag)
|
||||
}
|
||||
}
|
||||
|
||||
unpublishedTags = sortTags(unpublishedTags)
|
||||
|
||||
// 未アップロードのパッケージを処理
|
||||
for _, tag := range unpublishedTags {
|
||||
|
||||
if err := os.Chdir(workRoot); err != nil {
|
||||
fmt.Printf("[Error] Work Directory Change Failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// repositoryDirName ディレクトリが無ければtagタグをClone, あればtagタグをチェックアウト
|
||||
if _, err := os.Stat(repositoryRoot); os.IsNotExist(err) {
|
||||
if err := exec.Command("git", "clone", "-b", tag, addr, repositoryDirName).Run(); err != nil {
|
||||
fmt.Printf("[Error] clone failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
if err := os.Chdir(repositoryRoot); err != nil {
|
||||
fmt.Printf("[Error] directory change failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if err := os.Chdir(repositoryRoot); err != nil {
|
||||
fmt.Printf("[Error] directory change failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
if err := exec.Command("git", "checkout", tag).Run(); err != nil {
|
||||
fmt.Printf("[Error] checkout failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := exec.Command("git", "submodule", "update", "--init", "--recursive").Run(); err != nil {
|
||||
fmt.Printf("[Error] submodule update failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
if err := exec.Command("git", "lfs", "pull").Run(); err != nil {
|
||||
fmt.Printf("[Error] lfs pull failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := os.Chdir(packageRoot); err != nil {
|
||||
fmt.Printf("[Error] directory change failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// パッケージのアップロード
|
||||
if err := exec.Command("npm", "set", fmt.Sprintf("//%s/:_authToken", npmRegistry), npmToken).Run(); err != nil {
|
||||
fmt.Printf("[Error] npm auth failed. %s\n", err)
|
||||
continue
|
||||
}
|
||||
if !devMode {
|
||||
if err := exec.Command("npm", "publish", "--registry", fmt.Sprintf("https://%s/", npmRegistry)).Run(); err != nil {
|
||||
fmt.Printf("%s:%s@%s failed to publish. %s\n", repositoryName, dir, tag, err)
|
||||
} else {
|
||||
fmt.Printf("%s:%s@%s published.\n", repositoryName, dir, tag)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("%s:%s@%s dummy published.\n", repositoryName, dir, tag)
|
||||
}
|
||||
}
|
||||
|
||||
// 作業ディレクトリの削除
|
||||
if err := os.Chdir(workRoot); err != nil {
|
||||
fmt.Printf("[Error] Work Directory Change Failed. %s\n", err)
|
||||
}
|
||||
if err := os.RemoveAll(repositoryRoot); err != nil {
|
||||
fmt.Printf("[Error] Work Directory Remove Failed. %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// タグをソートする関数です。
|
||||
func sortTags(tags []string) []string {
|
||||
sort.Slice(tags, func(i, j int) bool {
|
||||
versionI := strings.Split(tags[i], ".")
|
||||
versionJ := strings.Split(tags[j], ".")
|
||||
|
||||
for k := 0; k < len(versionI) && k < len(versionJ); k++ {
|
||||
numI, _ := strconv.Atoi(versionI[k])
|
||||
numJ, _ := strconv.Atoi(versionJ[k])
|
||||
if numI != numJ {
|
||||
return numI < numJ
|
||||
}
|
||||
}
|
||||
return len(versionI) < len(versionJ)
|
||||
})
|
||||
|
||||
return tags
|
||||
}
|
||||
|
||||
// 指定されたリポジトリのタグ一覧を取得する関数です。
|
||||
func getRemoteTags(repoAddr string) ([]string, error) {
|
||||
// git ls-remote --tags コマンドを実行
|
||||
cmd := exec.Command("git", "ls-remote", "--tags", repoAddr)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 出力をパースしてタグを抽出
|
||||
lines := strings.Split(string(out), "\n")
|
||||
var tags []string
|
||||
for _, line := range lines {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
parts := strings.Split(line, "\t")
|
||||
if len(parts) < 2 {
|
||||
continue
|
||||
}
|
||||
tag := strings.Replace(parts[1], "refs/tags/", "", 1)
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
// 指定された npm レジストリとパッケージ名を使用して、npm パッケージのタグ一覧を取得する関数です。
|
||||
func getNpmTags(npmRepo string, packageName string) ([]string, error) {
|
||||
var url = fmt.Sprintf("%s/%s", npmRepo, packageName)
|
||||
|
||||
// HTTP GET リクエストを送信
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// レスポンスのボディを読み取る
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// JSONをパースしてmapに変換
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal(body, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["versions"] == nil {
|
||||
return nil, fmt.Errorf("versions not found")
|
||||
}
|
||||
|
||||
// バージョン情報一覧を取得
|
||||
var versions []string
|
||||
for version := range result["versions"].(map[string]interface{}) {
|
||||
versions = append(versions, version)
|
||||
}
|
||||
|
||||
return versions, nil
|
||||
}
|
||||
|
||||
// 指定されたリポジトリの package.json を取得する関数です。
|
||||
func getPackageJson(repoType RepoType, author string, repository string, tag string, dir string) (map[string]interface{}, error) {
|
||||
var url = fmt.Sprintf("%s/%s/%s/%s/%s/package.json", repoTypeMap[repoType], author, repository, tag, dir)
|
||||
|
||||
// HTTP GET リクエストを送信
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// レスポンスのボディを読み取る
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// JSONをパースしてmapに変換
|
||||
var result map[string]interface{}
|
||||
if err := json.Unmarshal(body, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 指定された npm レジストリ、ユーザー名、およびパスワードを使用してnpm 認証トークンを取得する関数です。
|
||||
func getNpmAuthToken(npmRegistry, npmUser, npmPass string) (string, error) {
|
||||
data := map[string]string{
|
||||
"name": npmUser,
|
||||
"password": npmPass,
|
||||
}
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("PUT", fmt.Sprintf("https://%s/-/user/org.couchdb.user:%s", npmRegistry, npmUser), bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.SetBasicAuth(npmUser, npmPass)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusCreated {
|
||||
return "", fmt.Errorf("failed to get token, status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var returnData map[string]interface{}
|
||||
if err := json.Unmarshal(body, &returnData); err != nil {
|
||||
return "", err
|
||||
}
|
||||
token, ok := returnData["token"].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("token not found in response")
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"addr": "https://github.com/AoiKamishiro/SubAssetEditor.git",
|
||||
"dir": "."
|
||||
"dir": ".",
|
||||
"tagRegex": "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
|
||||
}
|
||||
5
repos/com.github.siccity.xnode.json
Normal file
5
repos/com.github.siccity.xnode.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"addr":"https://github.com/siccity/xNode.git",
|
||||
"dir":".",
|
||||
"tagRegex": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
|
||||
}
|
||||
5
repos/com.rlabrecque.steamworks.net.json
Normal file
5
repos/com.rlabrecque.steamworks.net.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"addr": "https://github.com/rlabrecque/Steamworks.NET.git",
|
||||
"dir": "./com.rlabrecque.steamworks.net",
|
||||
"tagRegex": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
|
||||
}
|
||||
5
repos/com.zallist.universal-shadergraph-extensions.json
Normal file
5
repos/com.zallist.universal-shadergraph-extensions.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"addr": "https://github.com/Zallist/unity-universal-shadergraph-extensions.git",
|
||||
"dir": ".",
|
||||
"tagRegex": "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
|
||||
}
|
||||
5
repos/jp.hadashikick.vcontainer.json
Normal file
5
repos/jp.hadashikick.vcontainer.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"addr": "https://github.com/hadashiA/VContainer.git",
|
||||
"dir": "./VContainer/Assets/VContainer",
|
||||
"tagRegex": "^[1-9]+\\.[0-9]+\\.[0-9]+$"
|
||||
}
|
||||
Reference in New Issue
Block a user