diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index eb6ab6b..4403019 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -1,8 +1,8 @@ -name: CD Dev +name: cd-dev on: workflow_run: - workflows: ["CI"] + workflows: ["ci-tests"] types: - completed @@ -36,7 +36,6 @@ jobs: run: | echo "VITE_API_URL=${{ secrets.VITE_API_URL_DEV }}" > .env - - name: Build and push Docker image id: push uses: docker/build-push-action@v5 @@ -45,8 +44,8 @@ jobs: file: ./Dockerfile push: true tags: | - shampiniony/dishdash-miniapp:dev - shampiniony/dishdash-miniapp:dev-${{ env.COMMIT_SHORT_SHA }} + ${{ secrets.DOCKER_USERNAME }}/dishdash-miniapp:dev + ${{ secrets.DOCKER_USERNAME }}/dishdash-miniapp:dev-${{ env.COMMIT_SHORT_SHA }} - name: Trigger Watchtower to update dev container shell: bash diff --git a/.github/workflows/cd-production.yaml b/.github/workflows/cd-production.yaml index 07ee36d..4399d97 100644 --- a/.github/workflows/cd-production.yaml +++ b/.github/workflows/cd-production.yaml @@ -1,15 +1,20 @@ -name: Publish Docker image +name: CD-prod on: - workflow_run: - workflows: ["CI"] - types: - - completed + workflow_dispatch: + inputs: + tag_name: + description: Write tag for deploy + required: true jobs: + ci-tests: + uses: ./.github/workflows/ci-tests.yaml + push_to_registry: name: Push Docker image to Docker Hub - if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }} + needs: [ci-tests] + if: (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != '') runs-on: ubuntu-latest permissions: packages: write @@ -20,12 +25,6 @@ jobs: - name: Check out the repo uses: actions/checkout@v4 - - name: Set short git commit SHA - id: vars - run: | - calculatedSha=$(git rev-parse --short ${{ github.sha }}) - echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV - - name: Log in to Docker Hub uses: docker/login-action@v2 with: @@ -44,8 +43,8 @@ jobs: file: ./Dockerfile push: true tags: | - shampiniony/dishdash-miniapp:latest - shampiniony/dishdash-miniapp:${{ env.COMMIT_SHORT_SHA }} + ${{ secrets.DOCKER_USERNAME }}/dishdash-miniapp:latest + ${{ secrets.DOCKER_USERNAME }}/dishdash-miniapp:${{ github.event.inputs.tag_name }} - name: Trigger watchtower to update container(s) shell: bash diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml new file mode 100644 index 0000000..a75b883 --- /dev/null +++ b/.github/workflows/ci-build.yaml @@ -0,0 +1,18 @@ +name: ci-build + +on: + workflow_call: {} + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build docker image + run: docker compose build --progress plain diff --git a/.github/workflows/ci-tests-build.yaml b/.github/workflows/ci-tests.yaml similarity index 54% rename from .github/workflows/ci-tests-build.yaml rename to .github/workflows/ci-tests.yaml index ce576c2..ae49220 100644 --- a/.github/workflows/ci-tests-build.yaml +++ b/.github/workflows/ci-tests.yaml @@ -1,17 +1,10 @@ -name: CI +name: ci-tests -on: - push: - branches: [ "main", "dev" ] - pull_request: - branches: [ "main", "dev" ] +on: [workflow_call] jobs: - build: - runs-on: ubuntu-22.04 - steps: - uses: actions/checkout@v4 @@ -27,10 +20,4 @@ jobs: run: yarn lint - name: Run Unit Tests - run: yarn test - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build docker image - run: docker compose build + run: yarn test \ No newline at end of file