diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index c48141c..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,188 +0,0 @@ ---- -version: 2.1 - -commands: - s3deploy: - description: 'Deploy to S3' - parameters: - to: - type: string - cf_distribution_id: - type: string - dir: - type: string - steps: - - run: | - aws configure set preview.cloudfront true - - run: | - aws s3 sync ./<< parameters.dir >> s3://<< parameters.to >> \ - --acl public-read --delete \ - --cache-control max-age=31536000 - - run: | - aws cloudfront create-invalidation \ - --distribution-id << parameters.cf_distribution_id >> \ - --paths /\* - -jobs: - test: - docker: - - image: cypress/base:22.13.0 - working_directory: ~/repo - steps: - - checkout - - restore_cache: - keys: - - yarn-dependencies-cypress-{{ checksum "yarn.lock" }} - - yarn-dependencies-cypress- - - run: - name: Install dependencies - command: yarn install --frozen-lockfile - - save_cache: - key: yarn-dependencies-cypress-{{ checksum "yarn.lock" }} - paths: - - ~/.cache - - run: yarn lint - - run: yarn e2e:prod - - run: yarn test - build: - docker: - - image: cimg/node:22.13 - working_directory: ~/repo - steps: - - checkout - - restore_cache: - keys: - - yarn-dependencies-node-{{ checksum "yarn.lock" }} - - yarn-dependencies-node- - - run: - name: Install dependencies - command: yarn install --frozen-lockfile - - save_cache: - key: yarn-dependencies-node-{{ checksum "yarn.lock" }} - paths: - - ~/.cache - - run: - name: Set env variables - command: echo 'export VERSION=$(echo $CIRCLE_SHA1 | cut -c -7)' >> $BASH_ENV - - run: - name: build qa - command: yarn build - environment: - BUILD_PATH: 'qa' - GENERATE_SOURCEMAP: 'false' - VITE_NODE_ENV: 'QA' - - run: - name: build staging - command: yarn build - environment: - BUILD_PATH: 'staging' - GENERATE_SOURCEMAP: 'false' - VITE_NODE_ENV: 'STAGING' - - run: - name: build production - command: yarn build - environment: - BUILD_PATH: 'production' - GENERATE_SOURCEMAP: 'false' - VITE_NODE_ENV: 'PRODUCTION' - - persist_to_workspace: - root: build - paths: - - qa - - staging - - production - - deploy_qa: - docker: - - image: circleci/python:3.6-jessie - working_directory: ~/deploy - environment: - PUBLIC_URL: https://forms.qa.codeyourfuture.io - steps: - - attach_workspace: - at: . - - run: - name: Set env variables - command: echo 'export VERSION=$(echo $CIRCLE_SHA1 | cut -c -7)' >> $BASH_ENV - - run: - name: Install awscli - command: sudo pip install awscli - - s3deploy: - dir: qa - to: 'forms.qa.codeyourfuture.io' - cf_distribution_id: E2VFUDC8YCDBKS - - deploy_staging: - docker: - - image: circleci/python:3.6-jessie - working_directory: ~/deploy - environment: - PUBLIC_URL: https://forms.staging.codeyourfuture.io - steps: - - attach_workspace: - at: . - - run: - name: Set env variables - command: echo 'export VERSION=$(echo $CIRCLE_SHA1 | cut -c -7)' >> $BASH_ENV - - run: - name: Install awscli - command: sudo pip install awscli - - s3deploy: - dir: staging - to: 'forms.staging.codeyourfuture.io' - cf_distribution_id: E1SJFMKKCNFUGI - - deploy_production: - docker: - - image: circleci/python:3.6-jessie - working_directory: ~/deploy - environment: - PUBLIC_URL: https://forms.codeyourfuture.io - steps: - - attach_workspace: - at: . - - run: - name: Set env variables - command: echo 'export VERSION=$(echo $CIRCLE_SHA1 | cut -c -7)' >> $BASH_ENV - - run: - name: Install awscli - command: sudo pip install awscli - - s3deploy: - dir: production - to: 'forms.codeyourfuture.io' - cf_distribution_id: E3MHHTOV68A76Q - -workflows: - version: 2 - test_and_deploy: - jobs: - - test: - context: build - - build: - context: build - requires: - - test - - deploy_qa: - context: deployments_qa - requires: - - build - filters: - branches: - only: - - qa - - deploy_staging: - context: deployments_staging - requires: - - build - filters: - branches: - only: - - staging - - deploy_production: - context: deployments - requires: - - build - filters: - branches: - only: - - master diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..ebe32a6 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,69 @@ +name: Test, Build and Deploy + +on: + push: + branches: + - qa + - staging + - master + pull_request: + branches: + - qa + - staging + + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 + with: + node-version: 22 + cache: yarn + - run: yarn install --frozen-lockfile + - run: yarn lint + - run: yarn e2e:prod + - run: yarn test + + qa: + needs: test + if: github.ref == 'refs/heads/qa' + uses: ./.github/workflows/deploy.yml + with: + bucket: forms.qa.codeyourfuture.io + distribution: E2VFUDC8YCDBKS + environment: qa + node_env: QA + region: eu-west-1 + role: arn:aws:iam::732238248492:role/cyf-bot-qa-ci-role + url: https://forms.qa.codeyourfuture.io + + + staging: + needs: test + if: github.ref == 'refs/heads/staging' + uses: ./.github/workflows/deploy.yml + with: + bucket: forms.staging.codeyourfuture.io + distribution: E1SJFMKKCNFUGI + environment: staging + node_env: STAGING + region: eu-west-1 + role: arn:aws:iam::732238248492:role/cyf-bot-staging-ci-role + url: https://forms.staging.codeyourfuture.io + + + production: + needs: test + if: github.ref == 'refs/heads/master' + uses: ./.github/workflows/deploy.yml + with: + bucket: forms.codeyourfuture.io + distribution: E3MHHTOV68A76Q + environment: production + node_env: PRODUCTION + region: eu-west-1 + role: arn:aws:iam::732238248492:role/cyf-bot-production-ci-role + url: https://forms.codeyourfuture.io + diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..80f74b6 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,66 @@ +on: + workflow_call: + inputs: + bucket: + description: the name of the S3 bucket + required: true + type: string + distribution: + description: the id of the Cloudfront distribution + required: true + type: string + environment: + description: the name of the environment containing relevant secrets/variables + required: true + type: string + node_env: + description: the name of the environment for building + required: true + type: string + region: + description: AWS region for s3, cloudfront (defaults to 'eu-west-1') + default: 'eu-west-1' + required: false + type: string + role: + description: ARN of the AWS IAM role to assume via OIDC + required: true + type: string + url: + description: the public URL of the deployment (optional) + required: false + type: string + + + +jobs: + build-and-deploy: + runs-on: ubuntu-slim + permissions: + id-token: write + contents: read + environment: + name: ${{ inputs.environment }} + url: ${{ inputs.url }} + steps: + - uses: actions/checkout@v6 + - run: npm install --global yarn + - uses: actions/setup-node@v6 + with: + node-version: 22 + cache: yarn + - run: yarn install --frozen-lockfile + - run: yarn build + env: + BUILD_PATH: ${{ inputs.environment }} + GENERATE_SOURCEMAP: 'false' + VITE_NODE_ENV: ${{ inputs.node_env }} + - uses: aws-actions/configure-aws-credentials@v5 + with: + role-to-assume: ${{ inputs.role }} + aws-region: ${{ inputs.region }} + - uses: CodeYourFuture/internal-actions/.github/actions/deploy-webpage@main + with: + bucket: ${{ inputs.bucket }} + build-folder: ./build/${{ inputs.environment }} + distribution: ${{ inputs.distribution }} \ No newline at end of file