diff --git a/.github/workflows/web-s3-develop-push.yml b/.github/workflows/web-s3-develop-push.yml new file mode 100644 index 0000000..635003c --- /dev/null +++ b/.github/workflows/web-s3-develop-push.yml @@ -0,0 +1,92 @@ +name: Push in development branch +run-name: > + "Create PR FROM develop TO ${{ inputs.DESTINATION_PR }}: ${{ github.event.head_commit.message }}" + +on: + workflow_call: + inputs: + NODE_VERSION: + description: 'Node version to use' + type: string + default: 14.18.0 + required: false + DESTINATION_PR: + description: 'Branch to target MR' + type: string + default: testing + required: false + PR_TITLE: + type: string + description: "Title for the pr" + default: "Pushing develop" + required: false + SLACK_CHANNEL: + type: string + description: Slack channel to send notifications + required: false + secrets: + SLACK_WEBHOOK_URL: + required: true + +jobs: + + testing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.NODE_VERSION }} + - run: npm ci + - run: npm run lint --if-present + - run: npm run test --if-present + - run: echo "TEST SUCCESSFULLY" + + build: + needs: [ testing ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.NODE_VERSION }} + - run: npm ci + - run: npm run release + + + generate-pr: + needs: [ build ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: generate-pr + id: open-pr + uses: repo-sync/pull-request@v2 + with: + destination_branch: ${{ inputs.DESTINATION_PR }} + pr_title: ${{ inputs.PR_TITLE }} + - run: echo "PR GENERATED SUCCESSFULLY" + - name: Notify Slack + uses: steplix/cicd-notify@1.0.0 + with: + template: pr + status: ${{ job.status }} + channel: ${{ inputs.SLACK_CHANNEL }} + slack_webhook_url: ${{ secrets.SLACK_WEBHOOK }} + env: + PR_URL: ${{ steps.open-pr.outputs.pr_url }} + PR_NUMBER: ${{ steps.open-pr.outputs.pr_number }} + + + notify-failure: + if: failure() + needs: [ testing, build, generate-pr ] + runs-on: ubuntu-latest + steps: + - name: Notify Slack + uses: steplix/cicd-notify@1.0.0 + with: + template: 'push' + status: failure + slack_webhook_url: ${{ secrets.SLACK_WEBHOOK }} + channel: ${{ inputs.SLACK_CHANNEL }} \ No newline at end of file diff --git a/.github/workflows/web-s3-hotfix-push.yml b/.github/workflows/web-s3-hotfix-push.yml new file mode 100644 index 0000000..edb19bd --- /dev/null +++ b/.github/workflows/web-s3-hotfix-push.yml @@ -0,0 +1,105 @@ +name: Push Hotfix in master branch +run-name: > + Push: ${{ github.ref_name }} + +on: + workflow_call: + inputs: + NODE_VERSION: + description: 'Node version to use' + type: string + default: 14.18.0 + required: false + DESTINATION_PR_MASTER: + description: 'Branch to target MR' + type: string + default: master + required: false + DESTINATION_PR_DEVELOP: + description: 'Branch to target MR' + type: string + default: develop + required: false + SLACK_CHANNEL: + type: string + description: Slack channel to send notifications + required: false + secrets: + SLACK_WEBHOOK_URL: + required: true + +jobs: + + testing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.NODE_VERSION }} + - run: npm ci + - run: npm run lint --if-present + - run: npm run test --if-present + - run: echo "TEST SUCCESSFULLY" + + build: + needs: [ testing ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.NODE_VERSION }} + - run: npm ci + - run: npm run release + + generate-pr-to-master: + needs: [testing,build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: generate-pr + id: pr-to-main + uses: repo-sync/pull-request@v2 + with: + destination_branch: ${{ inputs.DESTINATION_PR_MASTER }} + pr_title: " is TAG VERSION INCREMENT: Pushing HOTFIX ${{ github.ref_name }} into ${{ inputs.DESTINATION_PR_MASTER }}" + - run: echo "PR TO ${{ inputs.DESTINATION_PR_MASTER }} GENERATED SUCCESSFULLY" + - name: Notify Slack + uses: steplix/cicd-notify@1.0.0 + with: + template: pr + status: ${{ job.status }} + channel: ${{ inputs.SLACK_CHANNEL }} + env: + PR_URL: ${{ steps.pr-to-main.outputs.pr_url }} + PR_NUMBER: ${{ steps.pr-to-main.outputs.pr_number }} + + generate-pr-to-develop: + needs: [testing,build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: generate-pr + id: open-pr + uses: repo-sync/pull-request@v2 + with: + destination_branch: ${{ inputs.DESTINATION_PR_DEVELOP }} + pr-title: "Pushing HOTFIX ${{ github.ref_name }} into ${{ inputs.DESTINATION_PR_DEVELOP }}" + + notify-failure: + runs-on: ubuntu-latest + needs: + - testing + - build + - generate-pr-to-master + - generate-pr-to-develop + if: failure() + continue-on-error: true + steps: + - name: Slack Notify + uses: steplix/cicd-notify@1.0.0 + with: + template: push + status: failure + channel: ${{ env.SLACK_CHANNEL }} \ No newline at end of file diff --git a/.github/workflows/web-s3-master-push.yml b/.github/workflows/web-s3-master-push.yml new file mode 100644 index 0000000..f4ec00d --- /dev/null +++ b/.github/workflows/web-s3-master-push.yml @@ -0,0 +1,99 @@ +name: Push in master branch +run-name: > + ${{ github.event.pull_request.title }} + +on: + workflow_call: + inputs: + NODE_VERSION: + description: 'Node version to use' + type: string + default: 14.18.0 + required: false + SLACK_CHANNEL: + type: string + description: Slack channel to send notifications + required: false + AWS_BUCKET: + type: string + description: Bucket S3 to copy files for deploy + required: true + TEXT-WHERE-SEARCH-FOR-PARAMETERS: + type: string + description: 'Message to parse. Defaults to head commit message' + required: false + default: ${{ github.event.head_commit.message }} + secrets: + SLACK_WEBHOOK_URL: + required: true + AWS_KEY_ID: + required: true + AWS_SECRET_ACCESS_KEY: + required: true + AWS_REGION: + required: true + + +jobs: + + tagging: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.bumped_tag.outputs.version }} + steps: + - uses: steplix/cicd-check-parameter@1.0.0 + id: args + with: + message: ${{ inputs.TEXT-WHERE-SEARCH-FOR-PARAMETERS}} + param-0: major + param-1: minor + + - name: Get bumping mode + id: bump-mode + run: echo "mode=${{ (steps.args.outputs.param-0 == 'true' && 'major') || (steps.args.outputs.param-1 == 'true' && 'minor') || 'patch' }}" >> $GITHUB_OUTPUT + + # Bump tag without affecting repository + - uses: zwaldowski/semver-release-action@v3 + name: Get bumped tag + id: bumped_tag + with: + bump: ${{ steps.bump-mode.outputs.mode }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + build-zip-upload: + needs: [ tagging ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.NODE_VERSION }} + - run: npm ci + - run: npm run release + #ZIP + - name: generate-zip + id: zip + run: cd out && tar -czvf ${{ needs.tagging.outputs.tag }}.tar.gz * + + #UPLOAD + - uses: aws-actions/configure-aws-credentials@v1.7.0 + with: + aws-access-key-id: ${{ secrets.AWS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + - name: copy files to S3 + run: | + aws s3 cp out/${{ needs.tagging.outputs.tag }}.tar.gz s3://${{ inputs.AWS_BUCKET }}/${{ needs.tagging.outputs.tag }}.tar.gz + + + notify: + if: ${{ always() }} + needs: [ tagging,build-zip-upload ] + runs-on: ubuntu-latest + steps: + - name: Notify Slack + uses: steplix/cicd-notify@0.0.17 + with: + template: 'push' + status: ${{ needs.tagging.result || needs.build-zip-upload.result }} + slack_webhook_url: ${{ secrets.SLACK_WEBHOOK }} \ No newline at end of file diff --git a/.github/workflows/web-s3-release-deploy.yml b/.github/workflows/web-s3-release-deploy.yml new file mode 100644 index 0000000..56c6de8 --- /dev/null +++ b/.github/workflows/web-s3-release-deploy.yml @@ -0,0 +1,81 @@ +name: Deployment to production +run-name: > + Production deployment ${{ github.event.release.tag_name }}: ${{ github.event.release.name }} + +on: + workflow_call: + inputs: + SLACK_CHANNEL: + type: string + description: Slack channel to send notifications + required: false + AWS_BUCKET: + type: string + description: Bucket S3 to copy files for deploy + required: true + AWS_BUCKET_ARTIFACT: + type: string + description: Bucket S3 to download artifact to deploy + required: true + AWS_CLOUDFRONT_DISTRIBUTION_ID: + type: string + description: CloudFront Distribution ID + required: true + secrets: + SLACK_WEBHOOK_URL: + required: true + AWS_KEY_ID: + required: true + AWS_SECRET_ACCESS_KEY: + required: true + AWS_REGION: + required: true + +jobs: + + ## DEPLOY + + download_unzip_deploy: + runs-on: ubuntu-latest + steps: + #DOWNLOAD + - uses: aws-actions/configure-aws-credentials@v1.7.0 + with: + aws-access-key-id: ${{ secrets.AWS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: download zip from S3 + run: | + aws s3 cp s3://${{ inputs.AWS_BUCKET_ARTIFACT }}/${{ github.event.release.tag_name }}.tar.gz . + #UNZIP + - name: mkdir + run: mkdir output + + - name: un-zip + id: unzip + run: tar -xvzf ${{ github.event.release.tag_name }}.tar.gz -C output + + #UPLOAD + + - name: copy files to S3 + run: | + aws s3 sync output s3://${{ inputs.AWS_BUCKET }} + - name: Cloudfront invalidation + run: | + aws cloudfront create-invalidation --distribution-id ${{ inputs.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" + + + + notify: + if: ${{ always() }} + needs: [ download_unzip_deploy ] + runs-on: ubuntu-latest + steps: + - name: Notify Slack + uses: steplix/cicd-notify@1.0.0 + with: + template: 'push' + status: ${{ needs.download_unzip_deploy.result}} + slack_webhook_url: ${{ secrets.SLACK_WEBHOOK }} + channel: ${{ inputs.SLACK_CHANNEL }} \ No newline at end of file diff --git a/.github/workflows/web-s3-testing-deploy.yml b/.github/workflows/web-s3-testing-deploy.yml new file mode 100644 index 0000000..eeff201 --- /dev/null +++ b/.github/workflows/web-s3-testing-deploy.yml @@ -0,0 +1,101 @@ +name: Push in testing branch +run-name: > + "Deploying testing and creating PR to ${{ inputs.DESTINATION_PR }}" + +on: + workflow_call: + inputs: + NODE_VERSION: + description: 'Node version to use' + type: string + default: 14.18.0 + required: false + DESTINATION_PR: + description: 'Branch to target MR' + type: string + default: master + required: false + SLACK_CHANNEL: + type: string + description: Slack channel to send notifications + required: false + AWS_BUCKET: + type: string + description: Bucket S3 to copy files for deploy + required: true + AWS_CLOUDFRONT_DISTRIBUTION_ID: + type: string + description: CloudFront Distribution ID + required: true + secrets: + SLACK_WEBHOOK_URL: + required: true + AWS_KEY_ID: + required: true + AWS_SECRET_ACCESS_KEY: + required: true + AWS_REGION: + required: true + +jobs: + + build_deploy: + runs-on: ubuntu-latest + steps: + #BUILD + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.NODE_VERSION }} + - run: npm ci + - run: npm run release + #UPLOAD + - uses: aws-actions/configure-aws-credentials@v1.7.0 + with: + aws-access-key-id: ${{ secrets.AWS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + - name: copy files to S3 + run: | + aws s3 sync out s3://${{ inputs.AWS_BUCKET }} + - name: Cloudfront invalidation + run: | + aws cloudfront create-invalidation --distribution-id ${{ inputs.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" + + + generate-pr: + needs: [ build_deploy ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: generate-pr + id: pr-to-main + uses: repo-sync/pull-request@v2 + with: + destination_branch: ${{ inputs.DESTINATION_PR }} + pr_title: "#patch is TAG VERSION INCREMENT: PUSHING testing INTO ${{ inputs.DESTINATION_PR }}" + - run: echo "PR GENERATED SUCCESSFULLY" + - name: Notify Slack + uses: steplix/cicd-notify@1.0.0 + with: + template: pr + status: ${{ job.status }} + channel: ${{ inputs.SLACK_CHANNEL }} + slack_webhook_url: ${{ secrets.SLACK_WEBHOOK }} + env: + PR_URL: ${{ steps.pr-to-main.outputs.pr_url }} + PR_NUMBER: ${{ steps.pr-to-main.outputs.pr_number }} + + notify-failure: + runs-on: ubuntu-latest + needs: [ build_deploy,generate-pr ] + if: failure() + continue-on-error: true + steps: + - name: Slack Notify + uses: steplix/cicd-notify@1.0.0 + with: + template: push + status: failure + channel: ${{ inputs.SLACK_CHANNEL }} + slack_webhook_url: ${{ secrets.SLACK_WEBHOOK }} \ No newline at end of file diff --git a/web/static-s3/github/web-s3-develop-push-cicd.yml b/web/static-s3/github/web-s3-develop-push-cicd.yml new file mode 100644 index 0000000..60cf50b --- /dev/null +++ b/web/static-s3/github/web-s3-develop-push-cicd.yml @@ -0,0 +1,21 @@ +name: Push in development branch +run-name: > + "Create PR FROM develop TO ${{ vars.DESTINATION_PR_ON_DEVELOP_WORKFLOW }}: ${{ github.event.head_commit.message }}" + +on: + push: + branches: + - develop + + +jobs: + + develop: + uses: steplix/cicd-steplix/.github/workflows/web-s3-develop-push.yml@feature/addStaticWebWorkflows + with: + NODE_VERSION: ${{ vars.NODE_VERSION }} + DESTINATION_PR: ${{ vars.DESTINATION_PR_ON_DEVELOP_WORKFLOW }} + PR_TITLE: "Pushing develop into ${{ vars.DESTINATION_PR_ON_DEVELOP_WORKFLOW }}" + SLACK_CHANNEL: ${{ vars.SLACK_CHANNEL }} + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} diff --git a/web/static-s3/github/web-s3-hotfix-push-cicd.yml b/web/static-s3/github/web-s3-hotfix-push-cicd.yml new file mode 100644 index 0000000..cf18af4 --- /dev/null +++ b/web/static-s3/github/web-s3-hotfix-push-cicd.yml @@ -0,0 +1,19 @@ +name: Push Hotfix in master branch +run-name: > + Push: ${{ github.ref_name }} + +on: + push: + branches: + - 'hotfix/**' + +jobs: + hotfix: + uses: steplix/cicd-steplix/.github/workflows/web-s3-hotfix-push.yml@feature/addStaticWebWorkflows + with: + NODE_VERSION: ${{ vars.NODE_VERSION }} + DESTINATION_PR_MASTER: ${{ vars.DESTINATION_PR_ON_TESTING_WORKFLOW }} + DESTINATION_PR_DEVELOP: develop + SLACK_CHANNEL: ${{ vars.SLACK_CHANNEL }} + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} diff --git a/web/static-s3/github/web-s3-production-push-cicd.yml b/web/static-s3/github/web-s3-production-push-cicd.yml new file mode 100644 index 0000000..43a5b49 --- /dev/null +++ b/web/static-s3/github/web-s3-production-push-cicd.yml @@ -0,0 +1,28 @@ +name: Push in master branch +run-name: > + ${{ github.event.pull_request.title }} + +on: + pull_request_target: + types: + - closed + branches: + - master + + +jobs: + + master: + uses: steplix/cicd-steplix/.github/workflows/web-s3-master-push.yml@feature/addStaticWebWorkflows + with: + NODE_VERSION: ${{ vars.NODE_VERSION }} + SLACK_CHANNEL: ${{ vars.SLACK_CHANNEL }} + AWS_BUCKET: ${{ vars.PROD_AWS_BUCKET_ARTIFACT }} + TEXT-WHERE-SEARCH-FOR-PARAMETERS: ${{ github.event.pull_request.title }} + + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + AWS_KEY_ID: ${{ secrets.TEST_AWS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ secrets.TEST_AWS_REGION }} + diff --git a/web/static-s3/github/web-s3-realease-production-deploy-cicd.yml b/web/static-s3/github/web-s3-realease-production-deploy-cicd.yml new file mode 100644 index 0000000..4fc5157 --- /dev/null +++ b/web/static-s3/github/web-s3-realease-production-deploy-cicd.yml @@ -0,0 +1,22 @@ +name: Deployment to production +run-name: > + Production deployment ${{ github.event.release.tag_name }}: ${{ github.event.release.name }} +on: + release: + types: [published] + + +jobs: + + production: + uses: steplix/cicd-steplix/.github/workflows/web-s3-release-deploy.yml@feature/addStaticWebWorkflows + with: + AWS_BUCKET: ${{ vars.PROD_AWS_BUCKET }} + AWS_BUCKET_ARTIFACT: ${{ vars.PROD_AWS_BUCKET_ARTIFACT }} + SLACK_CHANNEL: ${{ vars.SLACK_CHANNEL }} + AWS_CLOUDFRONT_DISTRIBUTION_ID: ${{ vars.PROD_AWS_CLOUDFRONT_DISTRIBUTION_ID }} + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + AWS_KEY_ID: ${{ secrets.PROD_AWS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ secrets.PROD_AWS_REGION }} diff --git a/web/static-s3/github/web-s3-testing-deploy-cicd.yml b/web/static-s3/github/web-s3-testing-deploy-cicd.yml new file mode 100644 index 0000000..ac83d9c --- /dev/null +++ b/web/static-s3/github/web-s3-testing-deploy-cicd.yml @@ -0,0 +1,24 @@ +name: Push in testing branch +run-name: > + "Deploying testing and creating PR to ${{ vars.DESTINATION_PR_ON_TESTING_WORKFLOW }}" +on: + push: + branches: + - testing + + +jobs: + + testing: + uses: steplix/cicd-steplix/.github/workflows/web-s3-testing-deploy.yml@feature/addStaticWebWorkflows + with: + NODE_VERSION: ${{ vars.NODE_VERSION }} + DESTINATION_PR: ${{ vars.DESTINATION_PR_ON_TESTING_WORKFLOW }} + SLACK_CHANNEL: ${{ vars.SLACK_CHANNEL }} + AWS_BUCKET: ${{ vars.TEST_AWS_BUCKET }} + AWS_CLOUDFRONT_DISTRIBUTION_ID: ${{ vars.TEST_AWS_CLOUDFRONT_DISTRIBUTION_ID }} + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + AWS_KEY_ID: ${{ secrets.TEST_AWS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ secrets.TEST_AWS_REGION }}