This commit is contained in:
2023-01-03 00:04:38 +00:00
commit 3f002872e3
925 changed files with 181049 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: SwaggerEditor@next build
on:
push:
branches: [ next ]
pull_request:
branches: [ next ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16.16
registry-url: https://npm.pkg.github.com/
scope: "@swagger-api"
- name: Cache npm cache files
id: cache-npm-cache-files
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-cache-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Cache Cypress binary
id: cache-cypress-binary
uses: actions/cache@v3
with:
path: cypress/cache
key: cypress-binary-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Lint commit message
if: github.ref != 'refs/heads/next' && github.actor != 'dependabot[bot]'
run: git log -1 --pretty=format:"%s" | npx commitlint
- name: Lint code
run: npm run lint
- name: Unit tests
run: npm test
env:
CI: true
- name: Build App artifacts
run: npm run build:app
- name: E2E Tests
run: npm run cy:ci
- name: Upload build artifacts
if: github.ref == 'refs/heads/next'
uses: actions/upload-artifact@v3
with:
name: build
path: ./build
@@ -0,0 +1,37 @@
name: Dependabot Merge Me!
on:
pull_request_target:
branches: [ master, next ]
jobs:
merge-me:
name: Merge me!
if: github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
# This first step will fail if there's no metadata and so the approval
# will not occur.
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1.3.5
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
# Here the PR gets approved.
- name: Approve a PR
if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }}
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
# Finally, tell dependabot to merge the PR if all checks are successful
- name: Instruct dependabot to squash & merge
if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }}
uses: mshick/add-pr-comment@v2
with:
repo-token: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
allow-repeats: true
message: |
@dependabot squash and merge
env:
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
@@ -0,0 +1,53 @@
# inspired by https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
name: Deploy SwaggerEditor@next to GitHub Pages
on:
workflow_run:
workflows: ["SwaggerEditor@next build", "SwaggerEditor@next nightly build"]
types:
- completed
branches: [next]
jobs:
deploy:
if: >
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.conclusion == 'success'
name: Deploy SwaggerEditor@next to GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: next
- name: 'Download build artifact'
uses: actions/github-script@v6
with:
script: |
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "build"
})[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/build.zip', Buffer.from(download.data));
- run: |
mkdir deploy-dir
unzip build.zip -d deploy-dir
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages # The branch the action should deploy to.
folder: deploy-dir # The folder the action should deploy.
clean: true # Automatically remove deleted files from the deploy branch
@@ -0,0 +1,32 @@
# inspired by https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
name: Deploy SwaggerEditor@next to Rancher🚢
on:
workflow_run:
workflows: ["Build & Push SwaggerEditor@next Docker image"]
types:
- completed
jobs:
deploy:
if: github.event.workflow_run.conclusion == 'success'
name: Deploy SwaggerEditor@next to Rancher
runs-on: ubuntu-latest
steps:
- name: Deploy Rancher🚢
run: |
ts="$(date +'%Y-%m-%dT%H:%M:%SZ' --utc)"
curl -s -D /dev/stderr -X PATCH \
-H "Authorization: Bearer ${RANCHER_BEARER_TOKEN}" \
-H 'Content-Type: application/strategic-merge-patch+json' \
"${RANCHER_URL}/k8s/clusters/${RANCHER_CLUSTER_ID}/apis/apps/v1/namespaces/${RANCHER_NAMESPACE}/${RANCHER_K8S_OBJECT_TYPE}/${RANCHER_K8S_OBJECT_NAME}" \
-d "{\"spec\": {\"template\": {\"metadata\": {\"annotations\": {\"cattle.io/timestamp\": \"${ts}\"}}}}}"
env:
RANCHER_BEARER_TOKEN: ${{ secrets.RANCHER_BEARER_TOKEN }}
RANCHER_CLUSTER_ID: 'c-n8zp2'
RANCHER_NAMESPACE: 'swagger-oss'
RANCHER_K8S_OBJECT_TYPE: 'daemonsets'
RANCHER_URL: ${{ secrets.RANCHER_URL }}
RANCHER_K8S_OBJECT_NAME: 'swagger-editor-next'
@@ -0,0 +1,74 @@
# inspired by https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
name: Build & Push SwaggerEditor@next Docker image
on:
workflow_run:
workflows: ["Release SwaggerEditor@next"]
types:
- completed
branches: [next]
jobs:
build-push:
if: github.event.workflow_run.conclusion == 'success'
name: Build & Push SwaggerEditor@next Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: next
- name: Download build artifact
uses: actions/github-script@v6
with:
script: |
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "build"
})[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/build.zip', Buffer.from(download.data));
- run: |
mkdir build
unzip build.zip -d build
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_SB_USERNAME }}
password: ${{ secrets.DOCKERHUB_SB_PASSWORD }}
- name: Build docker image and push
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386,linux/ppc64le,linux/s390x
tags: swaggerapi/swagger-editor:next-v5
- name: Build unprivileged docker image and push
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile.unprivileged
push: true
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386,linux/ppc64le,linux/s390x
tags: swaggerapi/swagger-editor:next-v5-unprivileged
@@ -0,0 +1,74 @@
# Do not modify this file.
# Github Actions only recognizes `workflow_run` and `workflow_dispatch`
# events that are located in the default branch
name: SwaggerEditor@next nightly build
on:
workflow_dispatch:
schedule:
- cron: '30 22 * * *'
jobs:
nightly-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
ref: next
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16.16
registry-url: https://npm.pkg.github.com/
scope: "@swagger-api"
- name: Cache npm cache files
id: cache-npm-cache-files
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-cache-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- name: Cache Cypress binary
id: cache-cypress-binary
uses: actions/cache@v3
with:
path: cypress/cache
key: cypress-binary-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
- name: Lint code
run: npm run lint
- name: unit tests
run: npm test
env:
CI: true
- name: Produce build artifacts
run: npm run build
- name: Produce npm artifact
run: npm pack
- name: E2E Tests
run: npm run cy:ci
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: build
path: ./build
- name: Upload npm artifact
uses: actions/upload-artifact@v3
with:
name: "swagger-api-swagger-editor-next.tgz"
path: ./swagger-api-swagger-editor-next-*.tgz
@@ -0,0 +1,92 @@
name: Release SwaggerEditor@next
on:
workflow_dispatch:
branches:
- next
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: false
submodules: true
ref: next
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
scope: "@swagger-api"
- name: Determine the next release version
uses: cycjimmy/semantic-release-action@v3
with:
dry_run: true
extra_plugins: |
@semantic-release/git
@semantic-release/exec
env:
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
- name: Nothing to release
if: ${{ env.NEXT_RELEASE_VERSION == '' }}
uses: actions/github-script@v6
with:
script: |
core.setFailed('Nothing to release')
- name: Install dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
- name: Prepare for the Release
env:
REACT_APP_VERSION: ${{ env.NEXT_RELEASE_VERSION }}
run: |
npm run lint
npm run test
npm run build:app
npm run cy:ci
npm run build:bundle:esm
npm run build:bundle:umd
- name: Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v3
with:
dry_run: false
extra_plugins: |
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.SWAGGER_BOT_GITHUB_TOKEN }}
- name: Release failed
if: steps.semantic.outputs.new_release_published == 'false'
uses: actions/github-script@v6
with:
script: |
core.setFailed('Release failed')
- name: Release published
run: |
echo ${{ steps.semantic.outputs.new_release_version }}
echo ${{ steps.semantic.outputs.new_release_major_version }}
echo ${{ steps.semantic.outputs.new_release_minor_version }}
echo ${{ steps.semantic.outputs.new_release_patch_version }}
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build
path: ./build