From c74be958465ba1ed6e29baa37d0d5a36b6e070bb Mon Sep 17 00:00:00 2001 From: AoiKamishiro Date: Wed, 14 Aug 2024 16:14:11 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=BF=E3=82=B0=E3=81=A8=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=83=B3=E3=81=AE=E6=89=B1=E3=81=84=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=83=BB=E6=94=B9=E8=A1=8C=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89LF=E3=81=AE=E5=BC=B7=E5=88=B6=E3=83=BB=E3=81=9D?= =?UTF-8?q?=E3=81=AE=E4=BB=96=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/devcontainer.json | 8 +-- .gitattributes | 5 ++ .github/dependabot.yml | 12 ++++ .vscode/settings.json | 3 + package.sh | 122 +++++++++++++++----------------- 5 files changed, 82 insertions(+), 68 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/dependabot.yml create mode 100644 .vscode/settings.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 967cd1c..84d3a14 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,10 +3,10 @@ { "name": "Alpine", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/base:alpine" + "image": "mcr.microsoft.com/devcontainers/base:alpine-3.20", - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, + // Features to add to the dev container. More info: https://containers.dev/features. + //"features": { } // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], @@ -19,4 +19,4 @@ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" -} \ No newline at end of file +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..832000b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.json text eol=lf +*.sh text eol=lf +*.yml text eol=lf +*.md text eol=lf +*.git* text eol=lf \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f33a02c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..457f44d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.analysis.typeCheckingMode": "basic" +} \ No newline at end of file diff --git a/package.sh b/package.sh index cdac1be..421bafa 100755 --- a/package.sh +++ b/package.sh @@ -1,4 +1,4 @@ -apk add curl git git-lfs icu-data-full jq npm uuidgen > /dev/null +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 @@ -6,20 +6,23 @@ Repo_Process() { # Prepare Variables local UUID=$(uuidgen) local WORK_ROOT=$1 - local ITEM=$2 - local ADDRBASE=$(echo $ITEM | jq -r '.addr') - local DIR=$(echo $ITEM | jq -r '.dir') - local NAME=$(echo $ITEM | jq -r '.name') - local DISP=$(echo $ITEM | jq -r '.displayName') - local DESC=$(echo $ITEM | jq -r '.description') - local TAG_REGEX=$(echo $ITEM | jq -r '.tagRegex') - local WORK_DIR=$(basename $ADDRBASE | sed 's/\.[^\.]*$//') - local GITLABX="oauth2:glpat-$GITLABTOKEN" - local ADDR=${ADDRBASE/GITLAB/$GITLABX} + 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 PACKAGE_ROOT="$WORK_ROOT/$WORK_DIR-$UUID" - local PACKAGE_DIR="$WORK_ROOT/$WORK_DIR-$UUID/$DIR" - local PACKAGE_PATH="$PACKAGE_DIR/package.json" + 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]+$" @@ -31,8 +34,7 @@ Repo_Process() { # Download latest version cd $WORK_ROOT - echo $ADDR - git clone $ADDR $WORK_DIR-$UUID + git clone $ADDR $REPO_NAME-$UUID >/dev/null 2>&1 cd $PACKAGE_ROOT local TAGS=$(git tag -l --sort authordate) @@ -41,77 +43,63 @@ Repo_Process() { for TAG in $TAGS; do # Check if tag is valid - if [[ $TAG =~ $TAG_REGEX ]]; then - echo "$TAG is valid tag." - else - echo "$TAG is not valid tag." + if [[ ! $TAG =~ $TAG_REGEX ]]; then + echo "$REPO_NAME:$DIR@$TAG is invalid tag." continue fi - cd $WORK_ROOT - rm -r $PACKAGE_ROOT - git clone -b $TAG $ADDR $WORK_DIR-$UUID - cd $PACKAGE_ROOT - git submodule update --init --recursive - git lfs pull + # Prepare Variables + local GITHUB_PACKAGE_ADDR="https://raw.githubusercontent.com/${AUTHOR_NAME}/${REPO_NAME}/${TAG}/${DIR}/package.json" - # Check if package.json is exists - if [ ! -e $PACKAGE_PATH ]; then - echo "$PACKAGE_PATH does not exist." + # 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 - cd $PACKAGE_DIR - - # Load Package.json - local PACKAGE=$(cat package.json) - - # Change Name - if [[ "$NAME" != null ]]; then - local PROCESS_NAME='.name|="'$NAME'"' - local PACKAGE=$(echo $PACKAGE | jq "$PROCESS_NAME" | jq -c .) - fi - - # Change DisplayName - if [[ "$DISP" != null ]]; then - local PROCESS_DISP='.displayName|="'$DISP'"' - local PACKAGE=$(echo $PACKAGE | jq "$PROCESS_DISP" | jq -c .) - fi - - # Change Description - if [[ "$DESC" != null ]]; then - local PROCESS_DESC='.description|="'$DESC'"' - local PACKAGE=$(echo $PACKAGE | jq "$PROCESS_DESC" | jq -c .) - fi - - # Update package.json - rm package.json - echo $PACKAGE >package.json - - local PACKAGE_NAME=$(cat $PACKAGE_PATH | jq -r .name) - local PACKAGE_VERSION=$(cat $PACKAGE_PATH | jq -r .version) + 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/$PACKAGE_NAME -o /dev/null -w '%{http_code}\n') + 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/$PACKAGE_NAME) + 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" == "$PACKAGE_VERSION" ]]; then + if [[ "$SVR_VER" == "$SEM_VERSION" ]]; then local EXIST_ON_SVR="true" break fi done if [[ "$EXIST_ON_SVR" == "true" ]]; then - echo "Package $PACKAGE_NAME@$PACKAGE_VERSION is already exist." + echo "$REPO_NAME:$DIR@$TAG is already published." continue fi - echo "Package $PACKAGE_NAME@$PACKAGE_VERSION will be published." + + # 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"'"}' @@ -119,7 +107,13 @@ Repo_Process() { 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/ + 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