feat(62305): merge #2
This file contains hidden or 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: ci-cd-typescript.yml | ||
|
Check failure on line 1 in .github/workflows/ci-cd-typescript.yml
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| DOCKER_USERNAME: | ||
| required: true | ||
| DOCKER_PASSWORD: | ||
| required: true | ||
| inputs: | ||
| checkAndTestOutsideDocker: | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| codeCoverageEnabled: | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| env: | ||
| IMAGE_NAME_MIXED_CASE: "${{ github.repository }}" | ||
| TEST_STAGE: tester | ||
| PRODUCTION_STAGE: production | ||
| jobs: | ||
| build-check-test-push: | ||
| name: Build, check, test, push | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| clean: 'true' | ||
| fetch-depth: 2 | ||
| - name: Install Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "lts/*" | ||
| cache: "npm" | ||
| - name: Install NPM dependencies | ||
| run: npm ci | ||
| - name: Check and test outside Docker | ||
| if: ${{ inputs.checkAndTestOutsideDocker }} | ||
| run: npm run check-and-build | ||
| - name: Upload coverage reports to Codecov | ||
| if: ${{ codeCoverageEnabled }} | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| - name: Upload test results to Codecov | ||
| if: ${{ codeCoverageEnabled && !cancelled() }} | ||
| uses: codecov/test-results-action@v1 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| - name: Lowercase Docker Image Name | ||
| run: | | ||
| echo "IMAGE_NAME=${IMAGE_NAME_MIXED_CASE,,}" >> "${GITHUB_ENV}" | ||
| - name: Extract docker metadata | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=edge,branch=main | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
| type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} | ||
| type=sha,format=long | ||
| - name: Setup Docker Buildx | ||
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' | ||
| uses: docker/setup-buildx-action@v3 | ||
| - name: Build and export to Docker | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| load: true | ||
| target: "${{ env.TEST_STAGE }}" | ||
| tags: "${{ env.IMAGE_NAME }}:${{ env.TEST_STAGE }}" | ||
| - name: Check and test | ||
| run: | | ||
| docker run --rm "${{ env.IMAGE_NAME }}:${{ env.TEST_STAGE }}" | ||
| - name: Login to Docker Hub | ||
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || contains(github.ref, 'refs/tags/')) | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
| - name: Build and push | ||
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || contains(github.ref, 'refs/tags/')) | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| push: true | ||
| target: "${{ env.PRODUCTION_STAGE }}" | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||