|
| 1 | +name: ci-cd-typescript.yml |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + dockerUser: |
| 6 | + required: true |
| 7 | + type: string |
| 8 | + dockerPassword: |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + uploadJarArtifact: |
| 12 | + required: false |
| 13 | + type: boolean |
| 14 | + default: false |
| 15 | + jarArtifactName: |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + jarArtifactPath: |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + checkAndTestOutsideDocker: |
| 22 | + required: false |
| 23 | + type: boolean |
| 24 | + default: false |
| 25 | + |
| 26 | + |
| 27 | +env: |
| 28 | + IMAGE_NAME_MIXED_CASE: "${{ github.repository }}" |
| 29 | + TEST_STAGE: tester |
| 30 | + PRODUCTION_STAGE: production |
| 31 | + |
| 32 | +jobs: |
| 33 | + build-check-test-push: |
| 34 | + name: Build, check, test, push |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + clean: 'true' |
| 41 | + fetch-depth: 2 |
| 42 | + |
| 43 | + - name: Install Node |
| 44 | + uses: actions/setup-node@v4 |
| 45 | + with: |
| 46 | + node-version: "lts/*" |
| 47 | + cache: "npm" |
| 48 | + |
| 49 | + - name: Install NPM dependencies |
| 50 | + run: npm ci |
| 51 | + |
| 52 | + - name: Check and test outside Docker |
| 53 | + if: ${{ inputs.checkAndTestOutsideDocker }} |
| 54 | + run: npm run check-and-build |
| 55 | + |
| 56 | + - name: Lowercase Docker Image Name |
| 57 | + run: | |
| 58 | + echo "IMAGE_NAME=${IMAGE_NAME_MIXED_CASE,,}" >> "${GITHUB_ENV}" |
| 59 | +
|
| 60 | + - name: Extract docker metadata |
| 61 | + id: meta |
| 62 | + uses: docker/metadata-action@v5 |
| 63 | + with: |
| 64 | + images: ${{ env.IMAGE_NAME }} |
| 65 | + tags: | |
| 66 | + type=edge,branch=main |
| 67 | + type=semver,pattern={{version}} |
| 68 | + type=semver,pattern={{major}}.{{minor}} |
| 69 | + type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} |
| 70 | + type=sha,format=long |
| 71 | + |
| 72 | + - name: Setup Docker Buildx |
| 73 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' |
| 74 | + uses: docker/setup-buildx-action@v3 |
| 75 | + |
| 76 | + - name: Build and export to Docker |
| 77 | + uses: docker/build-push-action@v6 |
| 78 | + with: |
| 79 | + context: . |
| 80 | + load: true |
| 81 | + target: "${{ env.TEST_STAGE }}" |
| 82 | + tags: "${{ env.IMAGE_NAME }}:${{ env.TEST_STAGE }}" |
| 83 | + |
| 84 | + - name: Check and test |
| 85 | + run: | |
| 86 | + docker run --rm "${{ env.IMAGE_NAME }}:${{ env.TEST_STAGE }}" |
| 87 | + |
| 88 | + - name: Login to Docker Hub |
| 89 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || contains(github.ref, 'refs/tags/')) |
| 90 | + uses: docker/login-action@v3 |
| 91 | + with: |
| 92 | + username: ${{ inputs.dockerUser }} |
| 93 | + password: ${{ inputs.dockerPassword }} |
| 94 | + |
| 95 | + - name: Build and push |
| 96 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || contains(github.ref, 'refs/tags/')) |
| 97 | + uses: docker/build-push-action@v6 |
| 98 | + with: |
| 99 | + context: . |
| 100 | + push: true |
| 101 | + target: "${{ env.PRODUCTION_STAGE }}" |
| 102 | + tags: ${{ steps.meta.outputs.tags }} |
| 103 | + labels: ${{ steps.meta.outputs.labels }} |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
0 commit comments