diff --git a/.editorconfig b/.editorconfig index 178260d5d..e86d443fd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,7 @@ insert_final_newline = true [{package.json,yarn.lock}] indent_size = 2 -[generators/*/templates/circleci.yaml.ejs] +[generators/*/templates/workflow.yaml.ejs] indent_size = 2 [generators/*/templates/ansible/**/*.yaml.ejs] diff --git a/generators/app/index.test.ts b/generators/app/index.test.ts index a0c15550f..6f87efd16 100644 --- a/generators/app/index.test.ts +++ b/generators/app/index.test.ts @@ -2,7 +2,6 @@ import fs from 'fs'; import path from 'path'; import YAML from 'yaml'; import helpers from 'yeoman-test'; -import * as CircleCI from '../../utils/circleci'; describe('When running the generator with React', () => { let root: string; @@ -33,16 +32,6 @@ describe('When running the generator with React', () => { expect(config.devDependencies.vite).toBeDefined(); }); - - test('It add the right dependencies to the deploy job', async () => { - const content = await fs.promises.readFile(path.resolve(root, '.circleci', 'config.yml'), 'utf8'); - const config = CircleCI.Config.fromRaw(YAML.parse(content)); - - expect(config.workflows.build?.jobs.deploy?.requires).toEqual([ - 'backend-archive', - 'frontend-archive', - ]); - }); }); describe('When running the generator with Next.js', () => { @@ -74,45 +63,6 @@ describe('When running the generator with Next.js', () => { expect(config.dependencies.next).toBeDefined(); }); - - test('It add the right dependencies to the deploy job', async () => { - const content = await fs.promises.readFile(path.resolve(root, '.circleci', 'config.yml'), 'utf8'); - const config = CircleCI.Config.fromRaw(YAML.parse(content)); - - expect(config.workflows.build?.jobs.deploy?.requires).toEqual([ - 'backend-archive', - 'frontend-archive', - ]); - }); -}); - -describe('When running the generator with Symfony', () => { - let root: string; - - beforeAll(async () => { - const result = await helpers.run(__dirname) - .withPrompts({ - backend: 'symfony', - contactEmail: 'test@example.com', - add: false, - twig: true, - }); - - root = result.cwd; - }); - - afterAll(async () => { - await fs.promises.rm(root, { recursive: true }); - }); - - test('It add the right dependencies to the deploy job', async () => { - const content = await fs.promises.readFile(path.resolve(root, '.circleci', 'config.yml'), 'utf8'); - const config = CircleCI.Config.fromRaw(YAML.parse(content)); - - expect(config.workflows.build?.jobs.deploy?.requires).toEqual([ - 'backend-build', - ]); - }); }); describe('When running the generator with Flutter', () => { diff --git a/generators/express/index.test.ts b/generators/express/index.test.ts index b9391318d..e394f25b8 100644 --- a/generators/express/index.test.ts +++ b/generators/express/index.test.ts @@ -3,7 +3,6 @@ import path from 'path'; import execa from 'execa'; import YAML from 'yaml'; import helpers from 'yeoman-test'; -import { Config } from '../../utils/circleci'; describe('When running the generator', () => { let root: string; @@ -90,12 +89,6 @@ describe('When running the generator with kubernetes deployment', () => { await fs.promises.rm(root, { recursive: true }); }); - test('It generates a valid CircleCI config', async () => { - const content = await fs.promises.readFile(path.join(root, '.circleci', 'config.yml'), 'utf8'); - - Config.fromRaw(YAML.parse(content)); - }); - test('It generates a valid terraform config', async () => { const cwd = path.join(root, 'environments', 'staging'); diff --git a/generators/express/index.ts b/generators/express/index.ts index fe11315a2..e47d783f2 100644 --- a/generators/express/index.ts +++ b/generators/express/index.ts @@ -23,7 +23,7 @@ class ExpressGenerator extends PackageGenerator { this.configureDockerCompose('docker-compose.yaml.ejs'); - this.configureCircleCI('circleci.yaml.ejs'); + this.renderTemplate('workflow.yaml.ejs', `.github/workflows/${packageName}.yaml`); switch (this.config.get('deployment')) { case DeploymentChoice.Ansible: @@ -32,10 +32,6 @@ class ExpressGenerator extends PackageGenerator { encrypt: createEncrypt(this.readDestination('ansible/vault_pass.txt').trim()), cookieSecret: cryptoRandomString({ length: 64, type: 'alphanumeric' }), }); - - this.updateCircleCIConfig((config) => { - config.workflows.build!.jobs.deploy!.requires.push(`${packageName}-archive`); - }); break; case DeploymentChoice.Kubernetes: { const packageVar = varName(packageName); diff --git a/generators/express/templates/circleci.yaml.ejs b/generators/express/templates/circleci.yaml.ejs deleted file mode 100644 index b9c5d46f8..000000000 --- a/generators/express/templates/circleci.yaml.ejs +++ /dev/null @@ -1,186 +0,0 @@ -version: '2.1' - -orbs: -<% if (deployment === 'kubernetes') { %> - docker: circleci/docker@2.0.1 -<% } %> - node: circleci/node@4.5.1 - -executors: - node: - docker: - - image: node:18.16.0 - -jobs: - <%= packageName %>-yarn-install: - executor: node - steps: - - checkout - - node/install-packages: - app-dir: <%= packagePath %> - include-branch-in-cache-key: false - pkg-manager: yarn - - persist_to_workspace: - root: . - paths: - - <%= packagePath %>/node_modules - - <%= packageName %>-lint: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: - command: yarn lint - - <%= packageName %>-test: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: - command: yarn test - -<% if (deployment === 'ansible') { %> - <%= packageName %>-build: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: echo "export default '${CIRCLE_SHA1}';" > src/version.ts - - run: - command: yarn build - environment: - NODE_ENV: production - - persist_to_workspace: - root: ~/project - paths: - - <%= packagePath %>/dist - - <%= packageName %>-archive: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: - command: yarn install --prod --frozen-lockfile - - run: - name: Create archive - command: | - tar --create --gzip --file=archive.tar.gz --owner=0 --group=0 \ - dist/ \ - node_modules/ \ - - store_artifacts: - path: archive.tar.gz - destination: <%= packageName %>.tar.gz - - persist_to_workspace: - root: ~/project - paths: - - <%= packagePath %>/archive.tar.gz - - <%= packageName %>-sentry-release: - docker: - - image: getsentry/sentry-cli:1.61.0 - entrypoint: '' - environment: - SENTRY_PROJECT: <%= projectName %>-<%= packageName %> - steps: - - attach_workspace: - at: ~/project - - run: sentry-cli releases new <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} - - run: sentry-cli releases files <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} upload-sourcemaps <%= packagePath %>/dist - - run: sentry-cli releases finalize <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} -<% } %> -<% if (deployment === 'kubernetes') { %> - <%= packageName %>-build: - executor: docker/docker - steps: - - setup_remote_docker: - version: 20.10.11 - - checkout - - docker/build: - image: <%= projectName %>-<%= packageName %> - path: <%= packagePath %> - docker-context: <%= packagePath %> - extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>")' - <%= packageName %>-build-and-push: - executor: docker/docker - steps: - - setup_remote_docker: - version: 20.10.11 - - checkout - - docker/build: - registry: $DOCKER_REGISTRY - image: <%= projectName %>-<%= packageName %> - tag: << pipeline.git.branch >> - path: <%= packagePath %> - docker-context: <%= packagePath %> - extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>")' - - docker/check: - registry: $DOCKER_REGISTRY - - docker/push: - registry: $DOCKER_REGISTRY - image: <%= projectName %>-<%= packageName %> - tag: << pipeline.git.branch >> -<% } %> - -workflows: - version: '2' - build: - jobs: - - <%= packageName %>-yarn-install - - <%= packageName %>-lint: - requires: - - <%= packageName %>-yarn-install - - <%= packageName %>-test: - requires: - - <%= packageName %>-lint -<% if (deployment === 'ansible') { %> - - <%= packageName %>-build: - requires: - - <%= packageName %>-test - - <%= packageName %>-archive: - requires: - - <%= packageName %>-build - - <%= packageName %>-sentry-release: - context: sentry.io - requires: - - <%= packageName %>-build - filters: - branches: - only: - - develop - - main -<% } %> -<% if (deployment === 'kubernetes') { %> - - <%= packageName %>-build-and-push: - context: - - docker-registry - requires: - - <%= packageName %>-test - filters: - branches: - only: - - develop - - main - - <%= packageName %>-build: - requires: - - <%= packageName %>-test - filters: - branches: - ignore: - - develop - - main -<% } %> diff --git a/generators/express/templates/deployment/ansible/package/deployment.yaml.ejs b/generators/express/templates/deployment/ansible/package/deployment.yaml.ejs index 20d739d69..97d302120 100644 --- a/generators/express/templates/deployment/ansible/package/deployment.yaml.ejs +++ b/generators/express/templates/deployment/ansible/package/deployment.yaml.ejs @@ -1,18 +1,16 @@ --- - import_role: - name: build + name: find_github_artifact vars: - job_name: <%= packageName %>-archive repository_name: <%= repositoryName %> + workflow_name: <%= packageName %> delegate_to: localhost + when: artifact_url is not defined - import_role: - name: deploy + name: deploy_artifact environment: '{{ <%= varName(packageName) %>_env }}' vars: path: /home/<%= packageName %> - artifact_path: <%= packageName %>.tar.gz - job_name: <%= packageName %>-archive - repository_name: <%= repositoryName %> before_finalize: - ./node_modules/.bin/typeorm --dataSource dist/infrastructure/database/data-source.js migration:run after_finalize: diff --git a/generators/express/templates/deployment/ansible/package/deployment_ci.yaml.ejs b/generators/express/templates/deployment/ansible/package/deployment_ci.yaml.ejs deleted file mode 100644 index 90bcbfff9..000000000 --- a/generators/express/templates/deployment/ansible/package/deployment_ci.yaml.ejs +++ /dev/null @@ -1,11 +0,0 @@ ---- -- import_role: - name: deploy - environment: '{{ <%= varName(packageName) %>_env }}' - vars: - path: /home/<%= packageName %> - artifact_file: '{{ playbook_dir }}/../<%= packagePath %>/archive.tar.gz' - before_finalize: - - ./node_modules/.bin/typeorm --dataSource dist/infrastructure/database/data-source.js migration:run - after_finalize: - - systemctl restart <%= packageName %> diff --git a/generators/express/templates/workflow.yaml.ejs b/generators/express/templates/workflow.yaml.ejs new file mode 100644 index 000000000..8515de230 --- /dev/null +++ b/generators/express/templates/workflow.yaml.ejs @@ -0,0 +1,109 @@ +name: <%= packageName %> + +on: + pull_request: + paths: <%= packagePath %>/** + push: + branches: + - main + - develop + +defaults: + run: + working-directory: <%= packagePath %> + +jobs: + code-style: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18.16.0 + cache: yarn + cache-dependency-path: <%= packagePath %>/yarn.lock + - run: yarn install --frozen-lockfile + - run: yarn lint + + test: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18.16.0 + cache: yarn + cache-dependency-path: <%= packagePath %>/yarn.lock + - run: yarn install --frozen-lockfile + - run: yarn test + +<%_ if (deployment === 'ansible') { _%> + build: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18.16.0 + cache: yarn + cache-dependency-path: <%= packagePath %>/yarn.lock + - run: yarn install --frozen-lockfile + - run: echo "export default '${{ github.sha }}';" > src/version.ts + - run: yarn build + env: + NODE_ENV: production + - run: yarn install --frozen-lockfile --prod + - run: | + tar --create \ + --file=archive.tar \ + --owner=0 \ + --group=0 \ + --exclude '*.map' \ + dist/ \ + node_modules/ \ + - uses: actions/upload-artifact@v3 + with: + name: <%= packageName %> + path: <%= packagePath %>/archive.tar + if-no-files-found: error + if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' + - uses: getsentry/action-release@v1 + env: + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_ORG: ${{ secrets.SENTRY_ORG }} + SENTRY_PROJECT: <%= projectName %>-<%= packageName %> + with: + ignore_missing: true + sourcemaps: dist + version_prefix: <%= projectName %>-<%= packageName %>@ + working_directory: <%= packagePath %> + if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' + deploy-staging: + if: github.ref == 'refs/heads/develop' + needs: [build] + uses: ./.github/workflows/deploy.yaml + with: + package: <%= packageName %> + secrets: inherit +<%_ } _%> +<%_ if (deployment === 'kubernetes') { _%> + build: + runs-on: ubuntu-22.04 + steps: + - uses: docker/setup-buildx-action@v2.5.0 + - uses: docker/login-action@v2.1.0 + with: + registry: ${{ secrets.STAGING_REGISTRY }} + username: ${{ secrets.STAGING_REGISTRY_LOGIN }} + password: ${{ secrets.STAGING_REGISTRY_PASSWORD }} + if: github.ref == 'refs/heads/develop' + - uses: docker/build-push-action@v4.0.0 + with: + context: '{{ defaultContext }}:<%= packagePath %>' + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ secrets.STAGING_REGISTRY }}/<%= projectName %>/<%= packageName %> + push: ${{ github.ref == 'refs/heads/develop' }} + build-args: | + VERSION=${{ github.sha }} +<%_ } _%> diff --git a/generators/next-js/index.test.ts b/generators/next-js/index.test.ts index 323c0114b..3a1e44522 100644 --- a/generators/next-js/index.test.ts +++ b/generators/next-js/index.test.ts @@ -3,7 +3,6 @@ import path from 'path'; import execa from 'execa'; import YAML from 'yaml'; import helpers from 'yeoman-test'; -import { Config } from '../../utils/circleci'; describe('When running the generator', () => { let root: string; @@ -64,12 +63,6 @@ describe('When running the generator with kubernetes deployment', () => { await fs.promises.rm(root, { recursive: true }); }); - test('It generates a valid CircleCI config', async () => { - const content = await fs.promises.readFile(path.join(root, '.circleci', 'config.yml'), 'utf8'); - - Config.fromRaw(YAML.parse(content)); - }); - test('It generates a valid terraform config', async () => { const cwd = path.join(root, 'environments', 'staging'); diff --git a/generators/next-js/index.ts b/generators/next-js/index.ts index b427d2c15..1295d915b 100644 --- a/generators/next-js/index.ts +++ b/generators/next-js/index.ts @@ -20,17 +20,13 @@ class NextJSGenerator extends PackageGenerator { this.configureDockerCompose('docker-compose.yaml.ejs'); - this.configureCircleCI('circleci.yaml.ejs'); + this.renderTemplate('workflow.yaml.ejs', `.github/workflows/${packageName}.yaml`); switch (this.config.get('deployment')) { case DeploymentChoice.Ansible: this.configureAnsible('deployment/ansible', { repositoryName: this.config.get('repositoryName'), }); - - this.updateCircleCIConfig((config) => { - config.workflows.build!.jobs.deploy!.requires.push(`${packageName}-archive`); - }); break; case DeploymentChoice.Kubernetes: { const packageVar = varName(packageName); diff --git a/generators/next-js/templates/circleci.yaml.ejs b/generators/next-js/templates/circleci.yaml.ejs deleted file mode 100644 index 3aed385f0..000000000 --- a/generators/next-js/templates/circleci.yaml.ejs +++ /dev/null @@ -1,152 +0,0 @@ -version: '2.1' - -orbs: -<% if (deployment === 'kubernetes') { %> - docker: circleci/docker@2.0.1 -<% } %> - node: circleci/node@4.5.1 - -executors: - node: - docker: - - image: node:18.16.0 - -jobs: - <%= packageName %>-yarn-install: - executor: node - steps: - - checkout - - node/install-packages: - app-dir: <%= packagePath %> - include-branch-in-cache-key: false - pkg-manager: yarn - - persist_to_workspace: - root: . - paths: - - <%= packagePath %>/node_modules - - <%= packageName %>-lint: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: - command: yarn lint - -<% if (deployment === 'ansible') { %> - <%= packageName %>-build: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: echo "export default '${CIRCLE_SHA1}';" > version.ts - - run: - command: yarn build - environment: - NODE_ENV: production - - persist_to_workspace: - root: ~/project - paths: - - <%= packagePath %>/build - - <%= packageName %>-archive: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: - command: yarn install --prod --frozen-lockfile - - run: - name: Create archive - command: | - tar --create --gzip --file=archive.tar.gz --owner=0 --group=0 \ - build/ \ - next.config.js \ - node_modules/ \ - public/ \ - - store_artifacts: - path: archive.tar.gz - destination: <%= packageName %>.tar.gz - - persist_to_workspace: - root: ~/project - paths: - - <%= packagePath %>/archive.tar.gz -<% } %> -<% if (deployment === 'kubernetes') { %> - <%= packageName %>-build: - executor: docker/docker - steps: - - setup_remote_docker: - version: 20.10.11 - - checkout - - docker/build: - image: <%= projectName %>-<%= packageName %> - path: <%= packagePath %> - docker-context: <%= packagePath %> - extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>")' - <%= packageName %>-build-and-push: - executor: docker/docker - steps: - - setup_remote_docker: - version: 20.10.11 - - checkout - - docker/build: - registry: $DOCKER_REGISTRY - image: <%= projectName %>-<%= packageName %> - tag: << pipeline.git.branch >> - path: <%= packagePath %> - docker-context: <%= packagePath %> - extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>")' - - docker/check: - registry: $DOCKER_REGISTRY - - docker/push: - registry: $DOCKER_REGISTRY - image: <%= projectName %>-<%= packageName %> - tag: << pipeline.git.branch >> -<% } %> - -workflows: - version: '2' - build: - jobs: - - <%= packageName %>-yarn-install - - <%= packageName %>-lint: - requires: - - <%= packageName %>-yarn-install -<% if (deployment === 'ansible') { %> - - <%= packageName %>-build: - requires: - - <%= packageName %>-lint - - <%= packageName %>-archive: - requires: - - <%= packageName %>-build -<% } %> -<% if (deployment === 'kubernetes') { %> - - <%= packageName %>-build-and-push: - context: - - docker-registry - requires: - - <%= packageName %>-test - filters: - branches: - only: - - develop - - main - - <%= packageName %>-build: - requires: - - <%= packageName %>-test - filters: - branches: - ignore: - - develop - - main -<% } %> diff --git a/generators/next-js/templates/deployment/ansible/package/deployment.yaml.ejs b/generators/next-js/templates/deployment/ansible/package/deployment.yaml.ejs index 4900d72fd..6de5059b0 100644 --- a/generators/next-js/templates/deployment/ansible/package/deployment.yaml.ejs +++ b/generators/next-js/templates/deployment/ansible/package/deployment.yaml.ejs @@ -1,17 +1,15 @@ --- - import_role: - name: build + name: find_github_artifact vars: - job_name: <%= packageName %>-archive repository_name: <%= repositoryName %> + workflow_name: <%= packageName %> delegate_to: localhost + when: artifact_url is not defined - import_role: - name: deploy + name: deploy_artifact environment: '{{ <%= varName(packageName) %>_env }}' vars: path: /home/<%= packageName %> - artifact_path: <%= packageName %>.tar.gz - job_name: <%= packageName %>-archive - repository_name: <%= repositoryName %> after_finalize: - systemctl restart <%= packageName %> diff --git a/generators/next-js/templates/deployment/ansible/package/deployment_ci.yaml.ejs b/generators/next-js/templates/deployment/ansible/package/deployment_ci.yaml.ejs deleted file mode 100644 index 066634d7f..000000000 --- a/generators/next-js/templates/deployment/ansible/package/deployment_ci.yaml.ejs +++ /dev/null @@ -1,9 +0,0 @@ ---- -- import_role: - name: deploy - environment: '{{ <%= varName(packageName) %>_env }}' - vars: - path: /home/<%= packageName %> - artifact_file: '{{ playbook_dir }}/../<%= packagePath %>/archive.tar.gz' - after_finalize: - - systemctl restart <%= packageName %> diff --git a/generators/next-js/templates/workflow.yaml.ejs b/generators/next-js/templates/workflow.yaml.ejs new file mode 100644 index 000000000..e5575a817 --- /dev/null +++ b/generators/next-js/templates/workflow.yaml.ejs @@ -0,0 +1,87 @@ +name: <%= packageName %> + +on: + pull_request: + paths: <%= packagePath %>/** + push: + branches: + - main + - develop + +defaults: + run: + working-directory: <%= packagePath %> + +jobs: + code-style: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18.16.0 + cache: yarn + cache-dependency-path: <%= packagePath %>/yarn.lock + - run: yarn install --frozen-lockfile + - run: yarn lint + +<%_ if (deployment === 'ansible') { _%> + build: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18.16.0 + cache: yarn + cache-dependency-path: <%= packagePath %>/yarn.lock + - run: yarn install --frozen-lockfile + - run: yarn build + env: + NODE_ENV: production + - run: yarn install --frozen-lockfile --prod + - run: | + tar --create \ + --file=archive.tar \ + --owner=0 \ + --group=0 \ + --exclude '*.map' \ + build/ \ + next.config.js \ + node_modules/ \ + public/ \ + - uses: actions/upload-artifact@v3 + with: + name: <%= packageName %> + path: <%= packagePath %>/archive.tar + if-no-files-found: error + if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' + deploy-staging: + if: github.ref == 'refs/heads/develop' + needs: [build] + uses: ./.github/workflows/deploy.yaml + with: + package: <%= packageName %> + secrets: inherit +<%_ } _%> +<%_ if (deployment === 'kubernetes') { _%> + build: + runs-on: ubuntu-22.04 + steps: + - uses: docker/setup-buildx-action@v2.5.0 + - uses: docker/login-action@v2.1.0 + with: + registry: ${{ secrets.STAGING_REGISTRY }} + username: ${{ secrets.STAGING_REGISTRY_LOGIN }} + password: ${{ secrets.STAGING_REGISTRY_PASSWORD }} + if: github.ref == 'refs/heads/develop' + - uses: docker/build-push-action@v4.0.0 + with: + context: '{{ defaultContext }}:<%= packagePath %>' + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ secrets.STAGING_REGISTRY }}/<%= projectName %>/<%= packageName %> + push: ${{ github.ref == 'refs/heads/develop' }} + build-args: | + VERSION=${{ github.sha }} +<%_ } _%> diff --git a/generators/react/index.test.ts b/generators/react/index.test.ts index 8b4041eb5..d9ce458fe 100644 --- a/generators/react/index.test.ts +++ b/generators/react/index.test.ts @@ -3,7 +3,6 @@ import path from 'path'; import execa from 'execa'; import YAML from 'yaml'; import helpers from 'yeoman-test'; -import { Config } from '../../utils/circleci'; describe('When running the generator', () => { let root: string; @@ -73,12 +72,6 @@ describe('When running the generator with kubernetes deployment', () => { await fs.promises.rm(root, { recursive: true }); }); - test('It generates a valid CircleCI config', async () => { - const content = await fs.promises.readFile(path.join(root, '.circleci', 'config.yml'), 'utf8'); - - Config.fromRaw(YAML.parse(content)); - }); - test('It generates a project with a valid terraform config', async () => { const cwd = path.join(root, 'environments', 'staging'); diff --git a/generators/react/index.ts b/generators/react/index.ts index 3125673fd..674de90cf 100644 --- a/generators/react/index.ts +++ b/generators/react/index.ts @@ -20,17 +20,13 @@ class CreateReactAppGenerator extends PackageGenerator { this.configureDockerCompose('docker-compose.yaml.ejs'); - this.configureCircleCI('circleci.yaml.ejs'); + this.renderTemplate('workflow.yaml.ejs', `.github/workflows/${packageName}.yaml`); switch (this.config.get('deployment')) { case DeploymentChoice.Ansible: this.configureAnsible('deployment/ansible', { repositoryName: this.config.get('repositoryName'), }); - - this.updateCircleCIConfig((config) => { - config.workflows.build!.jobs.deploy!.requires.push(`${packageName}-archive`); - }); break; case DeploymentChoice.Kubernetes: { const packageVar = varName(packageName); diff --git a/generators/react/templates/circleci.yaml.ejs b/generators/react/templates/circleci.yaml.ejs deleted file mode 100644 index a1acc45cf..000000000 --- a/generators/react/templates/circleci.yaml.ejs +++ /dev/null @@ -1,188 +0,0 @@ -version: '2.1' - -orbs: -<% if (deployment === 'kubernetes') { %> - docker: circleci/docker@2.0.1 -<% } %> - node: circleci/node@4.5.1 - -executors: - node: - docker: - - image: node:18.16.0 - -jobs: - <%= packageName %>-yarn-install: - executor: node - steps: - - checkout - - node/install-packages: - app-dir: <%= packagePath %> - include-branch-in-cache-key: false - pkg-manager: yarn - - persist_to_workspace: - root: . - paths: - - <%= packagePath %>/node_modules - - <%= packageName %>-lint: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: - command: yarn lint - -<% if (deployment === 'ansible') { %> - <%= packageName %>-build: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: echo "export default '${CIRCLE_SHA1}';" > src/version.ts - - run: - command: yarn build - environment: - NODE_ENV: production - - persist_to_workspace: - root: ~/project - paths: - - <%= packagePath %>/dist - - <%= packageName %>-archive: - executor: node - working_directory: ~/project/<%= packagePath %> - steps: - - checkout: - path: ~/project - - attach_workspace: - at: ~/project - - run: - name: Create archive - command: | - tar --create --gzip --file=archive.tar.gz --owner=0 --group=0 \ - dist/ \ - - store_artifacts: - path: archive.tar.gz - destination: <%= packageName %>.tar.gz - - persist_to_workspace: - root: ~/project - paths: - - <%= packagePath %>/archive.tar.gz - - <%= packageName %>-sentry-release: - docker: - - image: getsentry/sentry-cli:1.61.0 - entrypoint: '' - environment: - SENTRY_PROJECT: <%= projectName %>-<%= packageName %> - steps: - - attach_workspace: - at: ~/project - - run: sentry-cli releases new <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} - - run: sentry-cli releases files <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} upload-sourcemaps <%= packagePath %>/dist - - run: sentry-cli releases finalize <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} -<% } %> - -<% if (deployment === 'kubernetes') { %> - <%= packageName %>-build: - executor: docker/docker - steps: - - setup_remote_docker: - version: 20.10.11 - - checkout - - docker/build: - image: <%= projectName %>-<%= packageName %> - path: <%= packagePath %> - docker-context: <%= packagePath %> - extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>")' - <%= packageName %>-build-and-push: - executor: docker/docker - steps: - - setup_remote_docker: - version: 20.10.11 - - checkout - - docker/build: - registry: $DOCKER_REGISTRY - image: <%= projectName %>-<%= packageName %> - tag: << pipeline.git.branch >> - path: <%= packagePath %> - docker-context: <%= packagePath %> - extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>")' - - docker/build: - registry: $DOCKER_REGISTRY - image: <%= projectName %>-<%= packageName %> - tag: << pipeline.git.branch >>-sentry - path: <%= packagePath %> - docker-context: <%= packagePath %> - extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>") --target sentry' - - docker/check: - registry: $DOCKER_REGISTRY - - docker/push: - registry: $DOCKER_REGISTRY - image: <%= projectName %>-<%= packageName %> - tag: << pipeline.git.branch >> - - run: - name: Publish source maps to sentry - command: | - IMAGE="$DOCKER_REGISTRY/<%= projectName %>-<%= packageName %>:<< pipeline.git.branch >>-sentry" - ENV="--env SENTRY_AUTH_TOKEN --env SENTRY_ORG --env SENTRY_PROJECT=<%= projectName %>-<%= packageName %>" - VERSION=<%= projectName %>-<%= packageName %>@$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>") - - docker run --rm $ENV $IMAGE releases new $VERSION - docker run --rm $ENV $IMAGE releases files $VERSION upload-sourcemaps . - docker run --rm $ENV $IMAGE releases finalize $VERSION -<% } %> - -workflows: - version: '2' - build: - jobs: - - <%= packageName %>-yarn-install - - <%= packageName %>-lint: - requires: - - <%= packageName %>-yarn-install -<% if (deployment === 'ansible') { %> - - <%= packageName %>-build: - requires: - - <%= packageName %>-lint - - <%= packageName %>-archive: - requires: - - <%= packageName %>-build - - <%= packageName %>-sentry-release: - context: sentry.io - requires: - - <%= packageName %>-build - filters: - branches: - only: - - develop - - main -<% } %> -<% if (deployment === 'kubernetes') { %> - - <%= packageName %>-build-and-push: - context: - - docker-registry - - sentry.io - requires: - - <%= packageName %>-lint - filters: - branches: - only: - - develop - - main - - <%= packageName %>-build: - requires: - - <%= packageName %>-lint - filters: - branches: - ignore: - - develop - - main -<% } %> diff --git a/generators/react/templates/deployment/ansible/package/deployment.yaml.ejs b/generators/react/templates/deployment/ansible/package/deployment.yaml.ejs index f4f56b4cf..63b166ab5 100644 --- a/generators/react/templates/deployment/ansible/package/deployment.yaml.ejs +++ b/generators/react/templates/deployment/ansible/package/deployment.yaml.ejs @@ -1,19 +1,17 @@ --- - import_role: - name: build - delegate_to: localhost + name: find_github_artifact vars: - job_name: <%= packageName %>-archive repository_name: <%= repositoryName %> + workflow_name: <%= packageName %> + delegate_to: localhost + when: artifact_url is not defined - import_role: - name: deploy + name: deploy_artifact vars: path: /home/<%= packageName %> - artifact_path: <%= packageName %>.tar.gz before_finalize: - > sed --in-place --expression='s#