From f7da81c140094d5c530e3beea7bcc1462b73975e Mon Sep 17 00:00:00 2001 From: kafeman Date: Tue, 3 Dec 2024 23:23:09 +0100 Subject: [PATCH] Simplify the CI pipeline --- .github/workflows/build.yaml | 18 ------ .github/workflows/ci.yaml | 64 +++++++++++++++++++++ .github/workflows/deploy.yaml | 44 -------------- .github/workflows/lint.yaml | 13 ----- .github/workflows/main.yaml | 38 ------------ .github/workflows/pull-request-cleanup.yaml | 23 -------- .github/workflows/pull-request.yaml | 21 ------- 7 files changed, 64 insertions(+), 157 deletions(-) delete mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/deploy.yaml delete mode 100644 .github/workflows/lint.yaml delete mode 100644 .github/workflows/main.yaml delete mode 100644 .github/workflows/pull-request-cleanup.yaml delete mode 100644 .github/workflows/pull-request.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 35d1d02..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: Make a production build -on: - workflow_call: -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - - name: Install dependencies - run: npm ci - - run: npm run build - env: - NODE_ENV: production - - uses: actions/upload-artifact@v3 - with: - name: dist - path: ./dist diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..483ddd7 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,64 @@ +name: CI +on: + push: + paths-ignore: + - '**/README.md' + workflow_dispatch: +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + - name: Install dependencies + run: npm ci + - name: Make sure there are no type checking errors + run: npx tsc --noEmit + - run: npm run build + env: + NODE_ENV: production + - uses: actions/upload-artifact@v3 + with: + name: dist + path: ./dist + deploy_staging: + name: Staging + needs: build + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/download-artifact@v3 + with: + name: dist + path: dist + - run: | + mkdir ~/.ssh + echo "${{ vars.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts + eval `ssh-agent` + echo "$SSH_PRIVATE_KEY" | ssh-add - + rsync --recursive --verbose dist/ github@rocket.habrasanta.org:/var/www/beta.habrasanta.org + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Smoke test + run: curl --fail https://beta.habrasanta.org + deploy_production: + name: Production + needs: deploy_staging + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/download-artifact@v3 + with: + name: dist + path: dist + - run: | + mkdir ~/.ssh + echo "${{ vars.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts + eval `ssh-agent` + echo "$SSH_PRIVATE_KEY" | ssh-add - + rsync --recursive --verbose dist/ github@rocket.habrasanta.org:/var/www/habra-adm.ru + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Smoke test + run: curl --fail https://habra-adm.ru diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml deleted file mode 100644 index 6fe0d49..0000000 --- a/.github/workflows/deploy.yaml +++ /dev/null @@ -1,44 +0,0 @@ -name: Lint -on: - workflow_call: - inputs: - domain: - required: true - type: string - environment: - required: true - type: string - secrets: - SSH_PRIVATE_KEY: - required: true -permissions: - contents: read - deployments: write -jobs: - deploy: - name: Deploy - runs-on: ubuntu-latest - environment: - name: ${{ inputs.environment }} - url: https://${{ inputs.domain }} - steps: - - uses: actions/download-artifact@v3 - with: - name: dist - path: dist - - run: | - mkdir ~/.ssh - echo "${{ vars.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts - eval `ssh-agent` - echo "$SSH_PRIVATE_KEY" | ssh-add - - rsync --recursive --verbose dist/ github@rocket.habrasanta.org:/var/www/${{ inputs.domain }} - env: - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} - smoke_test: - name: Smoke test - needs: - - deploy - runs-on: ubuntu-latest - steps: - - name: Check if the URL is accessible - run: curl --fail https://${{ inputs.domain }} diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 2949141..0000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: Lint -on: - workflow_call: -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - - name: Install dependencies - run: npm ci - - name: Make sure there are no type checking errors - run: npx tsc --noEmit diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index 5011c75..0000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: Deploy to habra-adm.ru -on: - push: - branches: - - main - paths-ignore: - - '**/README.md' -concurrency: - group: deployment - cancel-in-progress: true -jobs: - lint: - name: Lint - uses: ./.github/workflows/lint.yaml - build: - name: Build - uses: ./.github/workflows/build.yaml - deploy_staging: - name: Staging - needs: - - lint - - build - uses: ./.github/workflows/deploy.yaml - with: - domain: beta.habrasanta.org - environment: staging - secrets: - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} - deploy_production: - name: Production - needs: - - deploy_staging - uses: ./.github/workflows/deploy.yaml - with: - domain: habra-adm.ru - environment: production - secrets: - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} diff --git a/.github/workflows/pull-request-cleanup.yaml b/.github/workflows/pull-request-cleanup.yaml deleted file mode 100644 index 47642ea..0000000 --- a/.github/workflows/pull-request-cleanup.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: Delete the pull-request-*.habrasanta.org website -on: - pull_request: - types: - - closed -jobs: - cleanup: - runs-on: ubuntu-latest - steps: - - name: Delete the environment on GitHub - uses: strumwolf/delete-deployment-environment@v2.2.3 - with: - token: ${{ secrets.DEPLOYMENTS_PAT }} - environment: pull-request-${{ github.event.number }}.habrasanta.org - - name: Delete files on the server - run: | - mkdir ~/.ssh - echo "${{ vars.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts - eval `ssh-agent` - echo "$SSH_PRIVATE_KEY" | ssh-add - - ssh github@rocket.habrasanta.org rm -rf /var/www/pull-request-${{ github.event.number }}.habrasanta.org - env: - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml deleted file mode 100644 index cb7862c..0000000 --- a/.github/workflows/pull-request.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Deploy to pull-request-*.habrasanta.org -on: - pull_request: -concurrency: - group: pull-request-${{ github.event.number }}-deployment - cancel-in-progress: true -jobs: - lint: - uses: ./.github/workflows/lint.yaml - build: - uses: ./.github/workflows/build.yaml - deploy: - needs: - - lint - - build - uses: ./.github/workflows/deploy.yaml - with: - domain: pull-request-${{ github.event.number }}.habrasanta.org - environment: pull-request-${{ github.event.number }} - secrets: - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}