From 122abe6373875d41a536a97d2c36c13efd947e02 Mon Sep 17 00:00:00 2001 From: Cameron Koegel Date: Thu, 10 Nov 2022 10:37:23 -0500 Subject: [PATCH] Update Workflows --- .github/pull_request_template.md | 13 ---- .github/workflows/main.yml | 79 -------------------- .github/workflows/publish-cli.yml | 120 ------------------------------ .github/workflows/publish.yml | 112 ++++++++++++++-------------- .github/workflows/sync.yml | 18 ----- 5 files changed, 55 insertions(+), 287 deletions(-) delete mode 100644 .github/pull_request_template.md delete mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/publish-cli.yml delete mode 100644 .github/workflows/sync.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 4933c4f3..00000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,13 +0,0 @@ -## What/Why/How? - -## Reference - -## Testing - -## Screenshots (optional) - -## Check yourself - -- [ ] Code is linted -- [ ] Tested -- [ ] All new/updated code is covered with tests diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 0c01bf26..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: Publish Docker image -on: - release: - types: [published] -jobs: - # push_to_registry: - # name: Push Docker image to GitHub Packages - # runs-on: ubuntu-latest - # permissions: - # packages: write - # contents: read - # steps: - # - name: Check out the repo - # uses: actions/checkout@v3 - # - name: Login to GitHub Container Registry - # uses: docker/login-action@v1 - # with: - # registry: ghcr.io - # username: ${{ github.repository_owner }} - # password: ${{ secrets.GITHUB_TOKEN }} - # - name: Prepare - # id: prep - # run: | - # DOCKER_IMAGE=ghcr.io/redocly/redoc/cli - # VERSION=edge - # if [[ $GITHUB_REF == refs/tags/* ]]; then - # VERSION=${GITHUB_REF#refs/tags/} - # elif [[ $GITHUB_REF == refs/heads/* ]]; then - # VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') - # elif [[ $GITHUB_REF == refs/pull/* ]]; then - # VERSION=pr-${{ github.event.number }} - # fi - # TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:latest" - # if [ "${{ github.event_name }}" = "push" ]; then - # TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" - # fi - # echo ::set-output name=version::${VERSION} - # echo ::set-output name=tags::${TAGS} - # echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - # - name: Push to GitHub Packages - # uses: docker/build-push-action@v3 - # with: - # context: ./cli - # push: ${{ github.event_name != 'pull_request' }} - # tags: ${{ steps.prep.outputs.tags }} - dockerhub: - name: Publish redoc image to DockerHub - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Docker meta - id: docker_meta - uses: crazy-max/ghaction-docker-meta@v1 - with: - images: redocly/redoc - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: . - file: ./config/docker/Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.docker_meta.outputs.tags }} - labels: ${{ steps.docker_meta.outputs.labels }} diff --git a/.github/workflows/publish-cli.yml b/.github/workflows/publish-cli.yml deleted file mode 100644 index eca538a6..00000000 --- a/.github/workflows/publish-cli.yml +++ /dev/null @@ -1,120 +0,0 @@ -name: Publish cli - -on: - push: - branches: - - main - -jobs: - bundle: - needs: [check-version-cli] - if: needs.check-version-cli.outputs.changed == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - - name: Cache node modules - uses: actions/cache@v3 - with: - path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: | - npm-${{ hashFiles('package-lock.json') }} - npm- - - run: npm ci && npm ci --prefix cli - - run: npm run bundle - - name: Store bundle artifact - uses: actions/upload-artifact@v3 - with: - name: bundles-cli - path: bundles - retention-days: 1 - unit-tests: - needs: [check-version-cli] - if: needs.check-version-cli.outputs.changed == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: npm ci && npm ci --prefix cli - - run: npm test - e2e-tests: - needs: [bundle] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: npm ci && npm ci --prefix cli - - name: Download bundled artifact - uses: actions/download-artifact@v3 - with: - name: bundles-cli - path: bundles - - run: npm run e2e - bundle-cli: - needs: [check-version-cli] - if: needs.check-version-cli.outputs.changed == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - - name: Cache node modules - uses: actions/cache@v3 - with: - path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: | - npm-${{ hashFiles('package-lock.json') }} - npm- - - name: Install dependencies - run: npm ci && npm ci --prefix cli - - name: Bundle - run: npm run compile:cli - - name: Store bundle artifact - uses: actions/upload-artifact@v3 - with: - name: cli - path: cli - retention-days: 1 - check-version-cli: - name: Check Version - runs-on: ubuntu-latest - outputs: - changed: ${{ steps.check.outputs.changed }} - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Set up Node.js - uses: actions/setup-node@v3 - - name: Check if version has been updated - id: check - uses: EndBug/version-check@v2.0.1 - with: - file-name: ./cli/package.json - file-url: https://unpkg.com/redoc-cli/package.json - static-checking: localIsNew - publish-cli: - needs: [bundle-cli, unit-tests, e2e-tests] - if: needs.check-version-cli.outputs.changed == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/setup-node@v3 - with: - node-version: '14.x' - registry-url: 'https://registry.npmjs.org' - - uses: actions/checkout@v3 - - name: Download cli bundled artifact - uses: actions/download-artifact@v3 - with: - name: cli - path: cli - - name: Cache node modules - uses: actions/cache@v3 - with: - path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: | - npm-${{ hashFiles('package-lock.json') }} - npm- - - name: Publish to NPM - run: cd cli/ && npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index adac3262..5c1812e0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,16 +1,20 @@ -name: Publish +name: Publish package to NPM on Release on: - push: - tags: - - v[0-9]*.[0-9]*.[0-9]* + release: + types: + - published jobs: bundle: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + - name: Cache node modules uses: actions/cache@v3 with: @@ -19,47 +23,74 @@ jobs: restore-keys: | npm-${{ hashFiles('package-lock.json') }} npm- - - run: npm ci && npm ci --prefix cli - - run: npm run bundle + + - name: CI + run: npm ci && npm ci --prefix cli + + - name: Bundle + run: npm run bundle + - name: Store bundle artifact uses: actions/upload-artifact@v3 with: name: bundles path: bundles retention-days: 1 + unit-tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - run: npm ci && npm ci --prefix cli - - run: npm test + - name: Checkout + uses: actions/checkout@v3 + + - name: CI + run: npm ci && npm ci --prefix cli + + - name: Unit Test + run: npm test + e2e-tests: needs: [bundle] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - run: npm ci && npm ci --prefix cli + - name: Checkout + uses: actions/checkout@v3 + + - name: CI + run: npm ci && npm ci --prefix cli + - name: Download bundled artifact uses: actions/download-artifact@v3 with: name: bundles path: bundles - - run: npm run e2e + + - name: E2e Test + run: npm run e2e + publish: - name: Publish to NPM - needs: [bundle, unit-tests, e2e-tests] + name: Publish runs-on: ubuntu-latest + if: ${{ !github.event.release.prerelease && github.event.release.target_commitish == 'main' }} steps: - - uses: actions/setup-node@v3 + - name: Set Release Version + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV + + - name: Setup Node + uses: actions/setup-node@v3 with: node-version: '14.x' registry-url: 'https://registry.npmjs.org' - - uses: actions/checkout@v3 + + - name: Checkout + uses: actions/checkout@v3 + - name: Download bundled artifacts uses: actions/download-artifact@v3 with: name: bundles path: bundles + - name: Cache node modules uses: actions/cache@v3 with: @@ -68,46 +99,13 @@ jobs: restore-keys: | npm-${{ hashFiles('package-lock.json') }} npm- + - name: Before deploy run: npm ci && npm run declarations - - name: Publish to NPM - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - publish-cdn: - name: Publish to CDN - needs: [bundle, unit-tests, e2e-tests] - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Configure AWS - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - name: Download all artifact - uses: actions/download-artifact@v3 - - name: Publish to S3 - run: npm run publish-cdn - - invalidate-cache: - name: Clear cache - runs-on: ubuntu-latest - needs: [publish, publish-cdn] - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Configure AWS - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - name: Invalidate cache - run: ./scripts/invalidate-cache.sh - shell: bash + - name: Publish npm Package + run: | + npm version $RELEASE_VERSION --no-git-tag-version + npm publish --access public env: - DISTRIBUTION: ${{ secrets.DISTRIBUTION }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml deleted file mode 100644 index 98e42d33..00000000 --- a/.github/workflows/sync.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Sync Files -on: - push: - branches: - - main - workflow_dispatch: -jobs: - sync: - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - name: Run GitHub File Sync - uses: Redocly/repo-file-sync-action@main - with: - GH_PAT: ${{ secrets.GH_PAT }} - COMMIT_PREFIX: 'sync:' - SKIP_PR: true