diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..b422d9f6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +name: Build + +on: + workflow_call: + inputs: + image: + required: true + type: string + context: + required: true + type: string + outputs: + tags: + type: string +jobs: + build: + name: Build + runs-on: ubuntu-latest + outputs: + image_tag: ${{ steps.meta.outputs.tags }} + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ inputs.image }} + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: ${{ inputs.context }} + push: true + pull: true + tags: ${{ steps.meta.outputs.tags }} \ No newline at end of file diff --git a/.github/workflows/pr-merge.yml b/.github/workflows/clean-registry.yml similarity index 97% rename from .github/workflows/pr-merge.yml rename to .github/workflows/clean-registry.yml index 119e0933..c144bad3 100644 --- a/.github/workflows/pr-merge.yml +++ b/.github/workflows/clean-registry.yml @@ -1,3 +1,5 @@ +name: Clean registry + on: pull_request: types: diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index 501e9d44..88276d5a 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -1,4 +1,5 @@ name: Main CI + on: pull_request: types: [opened, reopened, synchronize] @@ -24,48 +25,24 @@ jobs: build-backend: name: Build Backend - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: docker/setup-qemu-action@v3 - - uses: docker/setup-buildx-action@v3 - - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: ./backend - push: true - tags: ghcr.io/dnum-mi/basegun/basegun-backend:${{ github.head_ref || github.ref_name }} + uses: ./.github/workflows/build.yml + with: + image: ghcr.io/dnum-mi/basegun/basegun-backend + context: ./backend build-frontend: name: Build Frontend - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: docker/setup-qemu-action@v3 - - uses: docker/setup-buildx-action@v3 - - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: ./frontend - push: true - tags: ghcr.io/dnum-mi/basegun/basegun-frontend:${{ github.head_ref || github.ref_name }} + uses: ./.github/workflows/build.yml + with: + image: ghcr.io/dnum-mi/basegun/basegun-frontend + context: ./frontend test-backend: name: Test Backend needs: build-backend runs-on: ubuntu-latest container: - image: ghcr.io/dnum-mi/basegun/basegun-backend:${{ github.head_ref || github.ref_name }} + image: ${{ needs.build-backend.outputs.image_tag }} env: AWS_REGION: gra AWS_DEFAULT_REGION: gra @@ -104,4 +81,20 @@ jobs: test-e2e: name: Run E2E tests needs: [build-backend, build-frontend] - uses: ./.github/workflows/test-e2e.yml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Start stack using docker compose + run: docker compose -f docker-compose.yml -f docker-compose.override.ci.yml up -d + - name: Cypress run + uses: cypress-io/github-action@v6 + with: + working-directory: ./frontend + command: npm run test:e2e-ci + - name: Send artifacts + uses: actions/upload-artifact@v3 + if: ${{ failure() }} + with: + name: cypress-screenshots + path: | + ./frontend/cypress/screenshots/ diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml deleted file mode 100644 index 3ae752b4..00000000 --- a/.github/workflows/test-e2e.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Test E2E - -on: - workflow_call: - -jobs: - test-e2e: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Start stack using docker compose - run: docker compose -f docker-compose.yml -f docker-compose.override.ci.yml up -d - - - name: Cypress run - uses: cypress-io/github-action@v6 - with: - working-directory: ./frontend - command: npm run test:e2e-ci - - - name: Send artifacts - uses: actions/upload-artifact@v3 - if: ${{ failure() }} - with: - name: cypress-screenshots - path: | - ./frontend/cypress/screenshots/