diff --git a/.github/workflows/deploy-prod-env.yml b/.github/workflows/deploy-prod-env.yml deleted file mode 100644 index 5f47550a..00000000 --- a/.github/workflows/deploy-prod-env.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Deploy to Prod Env - -on: - workflow_dispatch: - inputs: - git-tag: - description: 'tag' - required: true - -env: - project-directory: ./ - -jobs: - deploy: - name: Deploy, requires approval - runs-on: ubuntu-latest - if: | - github.repository == 'Greenstand/treetracker-query-api' - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.git-tag }} - - name: get-npm-version - id: package-version - uses: martinbeentjes/npm-get-version-action@master - - name: Install kustomize - run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash - working-directory: ${{ env.project-directory }} - - 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: ${{ secrets.DIGITALOCEAN_PRODUCTION_TOKEN }} - - name: Save DigitalOcean kubeconfig - run: doctl kubernetes cluster kubeconfig save ${{ secrets.PRODUCTION_CLUSTER_NAME }} - - name: Update kubernetes resources - run: kustomize build deployment/overlays/prod | kubectl apply -n webmap --wait -f - - working-directory: ${{ env.project-directory }} diff --git a/.github/workflows/deploy-test-env.yml b/.github/workflows/deploy-test-env.yml deleted file mode 100644 index 1c4e1512..00000000 --- a/.github/workflows/deploy-test-env.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Deploy to Test Env - -on: - workflow_dispatch: - inputs: - git-tag: - description: 'tag' - required: true - -env: - project-directory: ./ - -jobs: - deploy: - name: Deploy, requires approval - runs-on: ubuntu-latest - if: | - github.repository == 'Greenstand/treetracker-query-api' - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.git-tag }} - - name: get-npm-version - id: package-version - uses: martinbeentjes/npm-get-version-action@master - - name: Install kustomize - run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash - working-directory: ${{ env.project-directory }} - - 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: ${{ secrets.TEST_DIGITALOCEAN_TOKEN }} - - name: Save DigitalOcean kubeconfig - run: doctl kubernetes cluster kubeconfig save ${{ secrets.TEST_CLUSTER_NAME }} - - name: Update kubernetes resources - run: kustomize build deployment/overlays/test | kubectl apply -n webmap --wait -f - - working-directory: ${{ env.project-directory }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..99c685eb --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,92 @@ +name: Deploy branches to channels + +on: + push: + branches: '**' + +env: + node_version: '18.x' + 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 }} \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index 36af2198..c37466e2 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npx lint-staged +npx lint-staged \ No newline at end of file diff --git a/.releaserc b/.releaserc index ebdc03a3..93fec767 100644 --- a/.releaserc +++ b/.releaserc @@ -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", diff --git a/package-lock.json b/package-lock.json index 60c6280d..db7564d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "treetracker-query-api", - "version": "1.70.7", + "version": "1.73.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "treetracker-query-api", - "version": "1.70.7", + "version": "1.73.0", "license": "GPL-3.0-or-later", "dependencies": { "@sentry/node": "^5.1.0",