Redocly/create-openapi-repo

CircleCI Support

springframeworkguru opened this issue · 1 comments

I got ReDoc-ly working with CircleCI, but it was kind of an adventure. Thought I'd share here in case someone wants to add support in the future.

GitHub Auth

I was not able to get authentication working with a personal token on a GitHub Organization. I found documentation indicating this is not supported. Changed to use ssl (which is nicely supported by CircleCI)

gh-pages

Needed to work around config of gh-pages. Mainly for the ssl auth. (Token Auth is hardcoded)

package.json

Added deploy:

{
  "name": "velo-payments-openapi",
  "version": "1.0.0",
  "dependencies": {
    "swagger-repo": "^2.0.0-rc.11"
  },
  "private": true,
  "scripts": {
    "start": "swagger-repo serve",
    "build": "swagger-repo build -o web_deploy",
    "test": "swagger-repo validate",
    "gh-pages": "swagger-repo gh-pages",
    "deploy": "gh-pages -a -m 'Deployed to Github Pages' -d 'web_deploy' -u 'CircleCI <john@springframework.guru>' "
  }
}

config.yml

CIrcleCI Build Configuration

  • $CIRCLE_BANCH - is a standard environment variable in the CircleCI build environment.
  • You will need to configure a SSH user key in your CircleCI build properties for this to work
version: 2.1
jobs:
    build:
        docker:
            -   image: circleci/node:11.9.0

        working_directory: ~/repo

        steps:
            - checkout

            # Download and cache dependencies
            -   restore_cache:
                    keys:
                        - v1-dependencies-{{ checksum "package.json" }}
                        # fallback to using the latest cache if no exact match is found
                        - v1-dependencies-

            - run: 'sudo npm install -g npm@latest'

            - run: npm install

            -   save_cache:
                    paths:
                        - node_modules
                    key: v1-dependencies-{{ checksum "package.json" }}

            - run:
                name: Deploy to gh-pages
                command: |

                    GIT_REPO="git@github.com:<YOUR REPO HERE>"

                    rm -rf ./node_modules/gh-pages/.cache

                    if [ $CIRCLE_BRANCH == "master" ]
                    then
                        echo "Running on Master"
                        npm run build

                        echo "Deploying"
                        npm run deploy -r $GIT_REPO
                    elif [ $CIRCLE_BRANCH != "master" ] && [ $CIRCLE_BRANCH != "gh-pages" ]
                    then
                        echo "Running NOT on master or gh-pages"
                        npm run build

                        DEST_DIR="/branch/$CIRCLE_BRANCH"

                        echo "Deploying to branch $DEST_DIR on $GIT_REPO"

                        npm run deploy -- "-r $GIT_REPO --dest $DEST_DIR"
                    else
                        echo Should not get here
                    fi
workflows:
    version: 2
    build-deploy:
        jobs:
            - build:
                  filters:
                      branches:
                          ignore:
                              - gh-pages

Out of scope of this project