Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Test to use package name variable #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get update && apt-get install -y -q --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 10.15.0
ENV NODE_VERSION 13.3.0

# # Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | bash \
Expand All @@ -43,8 +43,8 @@ ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

RUN npm config set strict-ssl false
RUN node -v
RUN npm install npm@6.12.0 -g
RUN npm install -g autorest
RUN npm install npm -g
RUN npm install -g autorest@latest
RUN npm i -g eol-converter-cli

COPY package.json /tmp/package.json
Expand Down
48 changes: 21 additions & 27 deletions build/create-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,30 @@

OUTPUT_PATH=${ENV_OUTPUT_PATH}
NAMESPACE=${ENV_NAMESPACE}
INPUT_PATH=./input/swagger.yml
INPUT_TMP=./input/swagger-tmp.yml
PACKAGE_NAME=${ENV_PACKAGE_NAME}
INPUT_PATH=./input/swagger.yaml

mkdir -p input
rm -rf input/*
rm -rf $OUTPUT_PATH/*
curl -o $INPUT_PATH ${ENV_YML_FILE_URL}

eolConverter "./input/swagger.yml"
eolConverter "./input/swagger.yaml"

line=$(head -n 1 $INPUT_PATH)

if echo "$line" | grep -q -E '^openapi: 3'
then
echo "Open api version 3 found. Convert to version 2"
npm install -g api-spec-converter
cp $INPUT_PATH $INPUT_TMP
api-spec-converter --from=openapi_3 --to=swagger_2 --syntax=yaml $INPUT_TMP > $INPUT_PATH
rm $INPUT_TMP
elif echo "$line" | grep -q -E '\"apiVersion\":\"1.'
then
echo "API version 1 found. Convert to version 2"
npm install -g api-spec-converter
cp $INPUT_PATH $INPUT_TMP
api-spec-converter --from=swagger_1 --to=swagger_2 --syntax=yaml $INPUT_TMP > $INPUT_PATH
rm $INPUT_TMP
if [ "$ENV_USE_OPENAPI_V3" = "true" ]; then
if [ "$ENV_USE_DATETIMEOFFSET" = "true" ]; then
autorest --v3 --use=/app --csharp --output-folder=$OUTPUT_PATH --namespace=$NAMESPACE --input-file=$INPUT_PATH --add-credentials --use-datetimeoffset --debug
else
autorest --v3 --use=/app --csharp --output-folder=$OUTPUT_PATH --namespace=$NAMESPACE --input-file=$INPUT_PATH --add-credentials --debug
fi
else
if [ "$ENV_USE_DATETIMEOFFSET" = "true" ]; then
autorest --use=/app --csharp --output-folder=$OUTPUT_PATH --namespace=$NAMESPACE --input-file=$INPUT_PATH --add-credentials --use-datetimeoffset --debug
else
autorest --use=/app --csharp --output-folder=$OUTPUT_PATH --namespace=$NAMESPACE --input-file=$INPUT_PATH --add-credentials --debug
fi
fi

autorest --use=/app --csharp --output-folder=$OUTPUT_PATH --namespace=$NAMESPACE --input-file=$INPUT_PATH --add-credentials

dotnet new classlib -n $NAMESPACE -o $OUTPUT_PATH
cat >NuGet.config <<EOL
<?xml version="1.0" encoding="utf-8"?><configuration><activePackageSource>
Expand All @@ -54,16 +48,16 @@ cat >NuGet.config <<EOL
</configuration>
EOL

dotnet add $OUTPUT_PATH/$NAMESPACE.csproj package Newtonsoft.Json -v 11.0.2
dotnet add $OUTPUT_PATH/$NAMESPACE.csproj package Microsoft.Rest.ClientRuntime -v 2.3.21
dotnet add $OUTPUT_PATH/$NAMESPACE.csproj package Agoda.Frameworks.Http -v 3.0.75
dotnet add $OUTPUT_PATH/$NAMESPACE.csproj package Microsoft.Extensions.Http.Polly
rm $OUTPUT_PATH/Class1.cs
dotnet add $OUTPUT_PATH/$PACKAGE_NAME.csproj package Newtonsoft.Json -v 11.0.2
dotnet add $OUTPUT_PATH/$PACKAGE_NAME.csproj package Microsoft.Rest.ClientRuntime -v 2.3.21
dotnet add $OUTPUT_PATH/$PACKAGE_NAME.csproj package Agoda.Frameworks.Http -v 3.0.75
dotnet add $OUTPUT_PATH/$PACKAGE_NAME.csproj package Microsoft.Extensions.Http.Pollyrm $OUTPUT_PATH/Class1.cs

dotnet pack $OUTPUT_PATH/$NAMESPACE.csproj -p:PackageVersion=$ENV_VERSION
dotnet pack $OUTPUT_PATH/$PACKAGE_NAME.csproj -p:PackageVersion=$ENV_VERSION

if [ "$ENV_SHOULD_PUSH_NUGET" = "true" ]; then
dotnet nuget push $OUTPUT_PATH/bin/Debug/$NAMESPACE.$ENV_VERSION.nupkg -k $ENV_NUGET_KEY -s https://bk-lib-nuget.agodadev.io/api/odata
dotnet nuget push $OUTPUT_PATH/bin/Debug/$PACKAGE_NAME.$ENV_VERSION.nupkg -k $ENV_NUGET_KEY -s https://bk-lib-nuget.agodadev.io/api/odata
else
echo "Nuget is not pushed because ENV_SHOULD_PUSH_NUGET is set to $ENV_SHOULD_PUSH_NUGET"
fi
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@ services:
### you can change .nupkg to .zip to view generated .dll file inside the package
# volumes:
# - C:/New folder/output4:/app/output
# - C:/New folder/input:/app/input
# - C:/fx:/app/fx
environment:
ENV_YML_FILE_URL: ${SWAGGER_URL}
ENV_OUTPUT_PATH: "/app/output"
ENV_NAMESPACE: ${NAMESPACE}
ENV_PACKAGE_NAME: ${PACKAGE_NAME}
ENV_VERSION: ${VERSION}
ENV_NUGET_KEY: ${NUGET_KEY}
ENV_SHOULD_PUSH_NUGET: ${SHOULD_UPLOAD_TO_NUGET}
ENV_USE_DATETIMEOFFSET: ${USE_DATETIMEOFFSET}
ENV_USE_OPENAPI_V3: ${USE_USE_OPENAPI_V3}
# To test on local
# ENV_YML_FILE_URL: "http://hk-qabapi-2a03:8080/api-docs/swagger.yaml"
# ENV_NAMESPACE: Agoda.BookingApi.Client.V2
# ENV_VERSION: 2.0.25
# ENV_NUGET_KEY: "5a77e143-0230-4db3-b23c-726b91f2a347"
# ENV_SHOULD_PUSH_NUGET: "false"
# ENV_USE_DATETIMEOFFSET: "true"
command: /app/build/create-project.sh