diff --git a/.github/actions/generate-and-test/action.yml b/.github/actions/generate-and-test/action.yml new file mode 100644 index 00000000000..d1d46c06a44 --- /dev/null +++ b/.github/actions/generate-and-test/action.yml @@ -0,0 +1,25 @@ +inputs: + language: + description: "The language to use for the generated project" + required: true + +runs: + using: "composite" + steps: + # - shell: bash + # run: cp -r /root/. $HOME # Workaround, because $HOME is set to /github/home inside the action run + - name: "client" + shell: bash + run: ./scripts/generate-and-test.sh ${{ inputs.language }} latest client + - name: "keto" + shell: bash + run: ./scripts/generate-and-test.sh ${{ inputs.language }} latest keto + - name: "kratos" + shell: bash + run: ./scripts/generate-and-test.sh ${{ inputs.language }} latest kratos + - name: "hydra" + shell: bash + run: ./scripts/generate-and-test.sh ${{ inputs.language }} latest hydra + - name: "oathkeeper" + shell: bash + run: ./scripts/generate-and-test.sh ${{ inputs.language }} latest oathkeeper diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml new file mode 100644 index 00000000000..42d490caa1e --- /dev/null +++ b/.github/workflows/pull-request.yaml @@ -0,0 +1,44 @@ +name: CI +on: + pull_request: + +jobs: + # test: + # runs-on: ubuntu-latest + # container: oryd/sdk:v0.0.53 + # defaults: + # run: + # shell: bash + # strategy: + # matrix: + # language: + # [ + # "elixir", + # "typescript", + # "rust", + # "golang", + # "java", + # "php", + # "python", + # "dotnet", + # "dart", + # ] + # steps: + # - uses: actions/checkout@v4 + # - name: Generate and Test - ${{ matrix.language }} + # uses: ./.github/actions/generate-and-test + # with: + # language: ${{ matrix.language }} + test-ruby: + runs-on: ubuntu-latest + steps: + - name: Set up Ruby 2.7 + uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 + with: + ruby-version: 2.7 + - uses: actions/checkout@v4 + - run: ls -la . + - name: Generate and Test + uses: ./.github/actions/generate-and-test + with: + language: ruby diff --git a/scripts/generate-and-test.sh b/scripts/generate-and-test.sh new file mode 100755 index 00000000000..7099b60609a --- /dev/null +++ b/scripts/generate-and-test.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -Eeuxo pipefail + +# Mainly used by the CI tasks + +# Both use the same arguments +./scripts/generate.sh $1 $2 $3 +./scripts/test.sh $1 $2 $3 diff --git a/scripts/generate.sh b/scripts/generate.sh index 824a4e691fc..153532de573 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -2,17 +2,18 @@ set -Eeuxo pipefail -cd "$( dirname "${BASH_SOURCE[0]}" )/.." +init() { + cd "$(dirname "${BASH_SOURCE[0]}")/.." -source scripts/prep.sh + source scripts/prep.sh -rm -rf config/client/*.proc.yml + rm -rf config/client/*.proc.yml -for f in config/client/* -do - echo "Processing $f..." - envsubst < "${f}" > "${f}.proc.yml" -done + for f in config/client/*; do + echo "Processing $f..." + envsubst <"${f}" >"${f}.proc.yml" + done +} cleanup() { rm "clients/${PROJECT}/java/git_push.sh" || true @@ -34,7 +35,7 @@ cleanup() { rm "clients/${PROJECT}/rust/.travis.yml" || true } -typescript () { +typescript() { echo "Generating TypeScript..." dir="clients/${PROJECT}/typescript" @@ -175,7 +176,7 @@ php() { cp "LICENSE" "clients/${PROJECT}/php" } -python () { +python() { echo "Generating Python..." dir="clients/${PROJECT}/python" @@ -193,7 +194,7 @@ python () { cp "LICENSE" "clients/${PROJECT}/python" } -ruby () { +ruby() { echo "Generating Ruby..." dir="clients/${PROJECT}/ruby" @@ -213,15 +214,18 @@ ruby () { file="${dir}/lib/${RUBY_PROJECT_NAME}/version.rb" - (sed "s/${VERSION}/${GEM_VERSION}/g" < "${file}") > tmp.$$.rb && mv tmp.$$.rb "${file}" + (sed "s/${VERSION}/${GEM_VERSION}/g" <"${file}") >tmp.$$.rb && mv tmp.$$.rb "${file}" - (cd ${dir}; sed "/^end.*/i \ gem 'psych', '~> 4.0.6'" < Gemfile) > tmp.$$.Gemfile && mv tmp.$$.Gemfile "${dir}/Gemfile" + ( + cd ${dir} + sed "/^end.*/i \ gem 'psych', '~> 4.0.6'" tmp.$$.Gemfile && mv tmp.$$.Gemfile "${dir}/Gemfile" cat "${file}" cp "LICENSE" "clients/${PROJECT}/ruby" } -golang () { +golang() { echo "Generating Golang..." dir="clients/${PROJECT}/go" @@ -249,7 +253,7 @@ golang () { fi } -dotnet () { +dotnet() { echo "Generating dotnet..." dir="clients/${PROJECT}/dotnet" @@ -268,7 +272,7 @@ dotnet () { cp "LICENSE" "clients/${PROJECT}/dotnet" } -dart () { +dart() { echo "Generating Dart..." dir="clients/${PROJECT}/dart" @@ -290,7 +294,7 @@ dart () { (cd $dir; command dart run build_runner build) } -rust () { +rust() { echo "Generating Rust..." dir="clients/${PROJECT}/rust" @@ -312,52 +316,74 @@ rust () { file="${dir}/Cargo.toml" if [ $project != "client" ]; then - (sed "s/${VERSION}/${RAW_VERSION}"'"\ndescription = "SDK Client for Ory '"${PROJECT_UCF}"'"\ndocumentation = "https:\/\/www.ory.sh\/'"${PROJECT}"'\/docs\/sdk"\nhomepage = "https:\/\/www.ory.sh"\nlicense = "Apache-2.0/g' < "${file}") > tmp.$$.rb && mv tmp.$$.rb "${file}" + (sed "s/${VERSION}/${RAW_VERSION}"'"\ndescription = "SDK Client for Ory '"${PROJECT_UCF}"'"\ndocumentation = "https:\/\/www.ory.sh\/'"${PROJECT}"'\/docs\/sdk"\nhomepage = "https:\/\/www.ory.sh"\nlicense = "Apache-2.0/g' <"${file}") >tmp.$$.rb && mv tmp.$$.rb "${file}" else - (sed "s/${VERSION}/${RAW_VERSION}"'"\ndescription = "SDK Client for Ory"\ndocumentation = "https:\/\/www.ory.sh\/docs\/sdk"\nhomepage = "https:\/\/www.ory.sh"\nlicense = "Apache-2.0/g' < "${file}") > tmp.$$.rb && mv tmp.$$.rb "${file}" + (sed "s/${VERSION}/${RAW_VERSION}"'"\ndescription = "SDK Client for Ory"\ndocumentation = "https:\/\/www.ory.sh\/docs\/sdk"\nhomepage = "https:\/\/www.ory.sh"\nlicense = "Apache-2.0/g' <"${file}") >tmp.$$.rb && mv tmp.$$.rb "${file}" fi cp "LICENSE" "clients/${PROJECT}/rust" } -elixir () { +elixir() { echo "Generating Elixir..." dir="clients/${PROJECT}/elixir" rm -rf "$dir" || true mkdir -p "$dir" - file="${dir}/mix.exs" # 7.4.0 openapi-generator-cli version-manager set 7.4.0 openapi-generator-cli generate -i "${SPEC_FILE}" \ - -g elixir \ - -o "$dir" \ - --git-user-id ory \ - --git-repo-id sdk \ - --git-host github.com \ - -c ./config/client/elixir.yml.proc.yml + -g elixir \ + -o "$dir" \ + --git-user-id ory \ + --git-repo-id sdk \ + --git-host github.com \ + -c ./config/client/elixir.yml.proc.yml - (sed "s/licenses:.*$/licenses: [\"Apache-2.0\"],\n links: %{\n \"GitHub\" => \"https:\/\/github.com\/ory\/sdk\",\n \"Website\" => \"https:\/\/www.ory.sh\",\n \"Documentation\" => \"https:\/\/www.ory.sh\/docs\",\n \"Product\" => \"https:\/\/console.ory.sh\"\n }/g" < "${file}") > tmp.$$.exs && mv tmp.$$.exs "${file}" - (sed "s/${VERSION}/${RAW_VERSION}/g" < "${file}") > tmp.$$.exs && mv tmp.$$.exs "${file}" + (sed "s/licenses:.*$/licenses: [\"Apache-2.0\"],\n links: %{\n \"GitHub\" => \"https:\/\/github.com\/ory\/sdk\",\n \"Website\" => \"https:\/\/www.ory.sh\",\n \"Documentation\" => \"https:\/\/www.ory.sh\/docs\",\n \"Product\" => \"https:\/\/console.ory.sh\"\n }/g" <"${file}") >tmp.$$.exs && mv tmp.$$.exs "${file}" + (sed "s/${VERSION}/${RAW_VERSION}/g" <"${file}") >tmp.$$.exs && mv tmp.$$.exs "${file}" cp "LICENSE" "clients/${PROJECT}/elixir" } -# elixir is broken right now: https://github.com/ory/sdk/issues/350 -#elixir -typescript -typescript_fetch -rust -golang -java -php -python - -# ruby is broken right now: https://github.com/ory/sdk/issues/357 -# ruby -dotnet -dart - -cleanup +generate() { + if [ "$(type -t $1)" = "function" ]; then + # Did we actually get a function ref? + FORCE_VERSION=$2 + FORCE_PROJECT=$3 + if [ $FORCE_VERSION = "latest" ]; then + FORCE_VERSION=$(cat spec/$FORCE_PROJECT/latest) + fi + + init + + $1 + + cleanup + else + echo "$1 is not a valid generator..." + fi +} + +if [ $# -lt 3 ]; then + # if no parameter is given, just execute all generators, as before. + # This is needed by the release pipeline + init + + # elixir + typescript + rust + golang + java + php + python + # ruby + dotnet + dart + + cleanup +else + generate $1 $2 $3 +fi diff --git a/scripts/test.sh b/scripts/test.sh index c5f4e219672..9633ce494e3 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -2,14 +2,14 @@ set -Eeuxo pipefail -cd "$( dirname "${BASH_SOURCE[0]}" )/.." +scriptsDir=$(dirname $(realpath "$0")) -source scripts/prep.sh +baseDir="$scriptsDir/.." -typescript () { +typescript() { echo "Testing TypeScript..." - dir="clients/${PROJECT}/typescript" + dir="$baseDir/clients/${PROJECT}/typescript" (cd "$dir" && npm i && npm run build) } @@ -23,35 +23,35 @@ typescript_fetch () { java () { echo "Testing Java..." - dir="clients/${PROJECT}/java" + dir="$baseDir/clients/${PROJECT}/java" (cd "$dir" && mvn test-compile) } php() { echo "Testing PHP..." - dir="clients/${PROJECT}/php" + dir="$baseDir/clients/${PROJECT}/php" (cd "$dir" && composer install && ./vendor/bin/phpunit) } -python () { +python() { echo "Testing Python..." - dir="clients/${PROJECT}/python" + dir="$baseDir/clients/${PROJECT}/python" (cd "$dir" && pip install -r requirements.txt && pip install -r test-requirements.txt && pytest --cov="$PYTHON_PACKAGE_NAME") } -ruby () { +ruby() { echo "Testing Ruby..." - dir="clients/${PROJECT}/ruby" + dir="$baseDir/clients/${PROJECT}/ruby" (cd "$dir" && rm "${RUBY_PROJECT_NAME}-${GEM_VERSION}.gem" || true && bundle install --path vendor/bundle && bundle exec rspec && gem build "${RUBY_PROJECT_NAME}.gemspec" && gem install "${RUBY_PROJECT_NAME}-${GEM_VERSION}.gem") } -golang () { +golang() { echo "Testing Golang..." - dir="clients/${PROJECT}/go" + dir="$baseDir/clients/${PROJECT}/go" if [ -f "$dir/README.md" ]; then # assuming swagger 3 in this case (cd "${dir}" && go mod tidy -compat=1.17 && go build -o "$(mktemp)" .) @@ -63,16 +63,16 @@ golang () { fi } -csharp () { +csharp() { echo "Testing C#..." - dir="clients/${PROJECT}/dotnet" - (cd "${dir}" && \ - VERSION="" dotnet build -c Release && \ + dir="$baseDir/clients/${PROJECT}/dotnet" + (cd "${dir}" && + VERSION="" dotnet build -c Release && VERSION="" dotnet test -c Release) } -dart () { +dart() { echo "Testing Dart..." dir="clients/${PROJECT}/dart" @@ -80,35 +80,78 @@ dart () { (cd "$dir" && command dart test .) } -rust () { +rust() { echo "Testing Rust..." - dir="clients/${PROJECT}/rust" + dir="$baseDir/clients/${PROJECT}/rust" (cd "$dir" && cargo test) } -elixir () { +elixir() { echo "Testing Elixir..." dir="clients/${PROJECT}/elixir" export MIX_ENV=prod - (cd "${dir}"; mix local.rebar --force) - (cd "${dir}"; mix local.hex --force) - (cd "${dir}"; mix deps.get) - (cd "${dir}"; mix deps.compile) - (cd "${dir}"; mix compile) - (cd "${dir}"; mix test) + ( + cd "${dir}" + mix local.rebar --force + ) + ( + cd "${dir}" + mix local.hex --force + ) + ( + cd "${dir}" + mix deps.get + ) + ( + cd "${dir}" + mix deps.compile + ) + ( + cd "${dir}" + mix compile + ) + ( + cd "${dir}" + mix test + ) } -# elixir -typescript -typescript_fetch -rust -golang -java -php -python -# ruby -dart -csharp +test() { + # Did we actually get a function ref? + if [ "$(type -t $1)" = "function" ]; then + FORCE_VERSION=$2 + FORCE_PROJECT=$3 + if [ $FORCE_VERSION = "latest" ]; then + # TODO: Make the client parameterized as well + FORCE_VERSION=$(cat spec/$FORCE_PROJECT/latest) + fi + + source scripts/prep.sh + + $1 + else + echo "$1 is not a valid generator..." + fi +} + +if [ $# -lt 3 ]; then + # if no parameter is given, just execute all generators, as before. + # This is needed by the release pipeline + # elixir + typescript + typescript_fetch + rust + golang + java + php + python + # ruby + dotnet + dart + +else + test $1 $2 $3 +fi