Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add unit test before git push #375

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions .github/workflows/deploy-prod-env.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/deploy-test-env.yml

This file was deleted.

92 changes: 92 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Deploy branches to channels

on:
push:
branches: '**'

env:
node_version: 12
project-directory: ./

jobs:
deploy:
name: Deploy branch to channel
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.branch-names.outputs.current_branch }}
channel: ${{ steps.get-channel.outputs.channel }}
DIGITALOCEAN_TOKEN: ${{ steps.resolver.outputs.DIGITALOCEAN_TOKEN }}
CLUSTER_NAME: ${{ steps.resolver.outputs.CLUSTER_NAME }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Get branch names
id: branch-names
uses: tj-actions/branch-names@v8

- name: Get npm version
id: package-version
uses: martinbeentjes/npm-get-version-action@master

- name: Get channel information
id: get-channel
run: |
BRANCH_NAME="${{ steps.branch-names.outputs.current_branch }}"
content=$(<.releaserc)
branches=$(jq -r '.branches | keys[]' <<< "$content")
for branch in $branches; do
branch_name=$(jq -r ".branches[$branch].name" <<< "$content")
if [[ "$BRANCH_NAME" =~ $branch_name ]]; then
channel=$(jq -r ".branches[$branch].channel" <<< "$content")
echo "::set-output name=channel::$channel"
exit 0
fi
done
echo "No channel found for branch $BRANCH_NAME"
exit 1
shell: bash

- name: Get deploy token
id: resolver
run: |
CHANNEL="${{ steps.get-channel.outputs.channel }}"
case "$CHANNEL" in
"rc")
echo "::set-output name=DIGITALOCEAN_TOKEN::${{ secrets.DIGITALOCEAN_PRODUCTION_TOKEN }}"
echo "::set-output name=CLUSTER_NAME::${{ secrets.PRODUCTION_CLUSTER_NAME }}"
;;
"alpha")
echo "::set-output name=DIGITALOCEAN_TOKEN::${{ secrets.TEST_DIGITALOCEAN_TOKEN }}"
echo "::set-output name=CLUSTER_NAME::${{ secrets.TEST_CLUSTER_NAME }}"
;;
*)
echo "No token found for channel $CHANNEL"
exit 1
;;
esac
shell: bash

- name: Deploy to channel
id: deploy
run: |
echo "Branch: ${{ steps.branch-names.outputs.current_branch }}"
echo "Channel: ${{ steps.get-channel.outputs.channel }}"
echo "DIGITALOCEAN_TOKEN: ${{ steps.resolver.outputs.DIGITALOCEAN_TOKEN }}"
echo "CLUSTER_NAME: ${{ steps.resolver.outputs.CLUSTER_NAME }}"

- name: Run kustomize
run: (cd ./deployment/base && ../../kustomize edit set image greenstand/treetracker-query-api:${{ steps.package-version.outputs.current-version }} )
working-directory: ${{ env.project-directory }}

- name: Install doctl for kubernetes
uses: digitalocean/action-doctl@v2
with:
token: ${{ steps.resolver.outputs.DIGITALOCEAN_TOKEN }}

- name: Save DigitalOcean kubeconfig
run: doctl kubernetes cluster kubeconfig save ${{ steps.resolver.outputs.CLUSTER_NAME }}

- name: Update kubernetes resources
run: kustomize build deployment/overlays/prod | kubectl apply -n webmap --wait -f -
working-directory: ${{ env.project-directory }}
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npm run test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our goal is to add unit test checking for the new pull request, so we need to add it into our github action.

npm run test
19 changes: 18 additions & 1 deletion .releaserc
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"branches": ["main"],
"branches": [
{
"name":"main",
"channel": "rc"
},
{
"name":"alpha/*",
"channel": "alpha"
},
{
"name":"beta/*",
"channel": "beta"
},
{
"name":"rc/*",
"channel": "rc"
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
);

// app allow cors
app.use(cors());
app.use(cors());//111

Check failure on line 38 in server/app.ts

View workflow job for this annotation

GitHub Actions / Run all tests

Expected exception block, space or tab after '//' in comment

/*
* Check request
Expand Down
Loading