ci: update the commit status with result of tests #503
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy guidance site to production | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: [ main ] | |
push: | |
branches: [ main ] | |
env: | |
HUSKY: 0 | |
GITHUB_DEPLOY_KEY: ${{ secrets.GH_DEPLOY_KEY }} | |
ECR_NAME: ${{ secrets.ECR_NAME }} | |
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | |
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 'lts/*' | |
- run: npm ci | |
- run: npm run build:package | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: mojds-package | |
path: package | |
- run: npm run build:dist | |
- run: ENV="production" npm run build:docs | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: mojds-dist | |
path: dist | |
test: | |
runs-on: ubuntu-latest | |
needs: build | |
strategy: | |
matrix: | |
node-version: [14.x, 16.x, 18.x, 20.x, 21.x, 22.x] | |
steps: | |
- name: Set commit status as pending | |
uses: myrotvorets/set-commit-status-action@master | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: pending | |
context: deploy tests | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: npm install | |
run: npm install | |
- name: Run JS tests | |
run: npm run test:js | |
- uses: actions/download-artifact@v4 | |
with: | |
name: mojds-package | |
path: package | |
- name: Test that sass can be compiled | |
run: npm run test:sass | |
- name: Set final commit status | |
uses: myrotvorets/set-commit-status-action@master | |
if: always() | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
context: deploy tests | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [build, test] | |
if: github.event_name == 'push' | |
permissions: | |
id-token: write | |
contents: read | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }} | |
aws-region: ${{ vars.ECR_REGION }} | |
- uses: aws-actions/amazon-ecr-login@v2 | |
id: login-ecr | |
- run: | | |
docker build --build-arg GITHUB_DEPLOY_KEY="${GITHUB_DEPLOY_KEY}" --target=production -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . | |
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG | |
cat kubernetes-deploy-production.tpl | envsubst > kubernetes-deploy-production.yaml | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPOSITORY: ${{ vars.ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ github.sha }} | |
BRANCH: "production" | |
- run: | | |
echo "${KUBE_CERT}" > ca.crt | |
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER} | |
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN} | |
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE} | |
kubectl config use-context ${KUBE_CLUSTER} | |
kubectl -n ${KUBE_NAMESPACE} apply -f kubernetes-deploy-production.yaml | |
env: | |
KUBE_CERT: ${{ secrets.KUBE_CERT }} | |
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }} | |
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | |