diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml new file mode 100644 index 0000000..8f986d2 --- /dev/null +++ b/.github/workflows/build_and_push.yml @@ -0,0 +1,37 @@ +name: Build and Push + +on: + workflow_call: + +jobs: + build_and_push: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push API image + run: | + docker build -t docker.io/prajjwalyd/api:latest ./api + docker push docker.io/prajjwalyd/api:latest + + - name: Build and push URL-Shortener image + run: | + docker build -t docker.io/prajjwalyd/url-shortener:latest ./url-shortener + docker push docker.io/prajjwalyd/url-shortener:latest + + - name: Build and push QR-Code-Generator image + run: | + docker build -t docker.io/prajjwalyd/qr-code-generator:latest ./qr-code-generator + docker push docker.io/prajjwalyd/qr-code-generator:latest + + - name: Build and push Analytics image + run: | + docker build -t docker.io/prajjwalyd/analytics:latest ./analytics + docker push docker.io/prajjwalyd/analytics:latest diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18a25d3..b4fc3ea 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: CI/CD Pipeline +name: Pipeline on: push: @@ -9,56 +9,13 @@ on: - main jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 + setup: + uses: ./.github/workflows/setup.yml - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: '1.22' + test: + needs: setup + uses: ./.github/workflows/test.yml - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.9' - - - name: Run tests for QR Code Generator - working-directory: qr-code-generator - run: | - go test -v ./... - - - name: Install pytest - run: pip install flask pytest - - - name: Run tests for URL Shortener - working-directory: url-shortener - run: pytest test_url_shortener.py - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and push API image - run: | - docker build -t docker.io/prajjwalyd/api:latest ./api - docker push docker.io/prajjwalyd/api:latest - - name: Build and push URL-Shortener image - run: | - docker build -t docker.io/prajjwalyd/url-shortener:latest ./url-shortener - docker push docker.io/prajjwalyd/url-shortener:latest - - name: Build and push QR-Code-Generator image - run: | - docker build -t docker.io/prajjwalyd/qr-code-generator:latest ./qr-code-generator - docker push docker.io/prajjwalyd/qr-code-generator:latest - - name: Build and push Analytics image - run: | - docker build -t docker.io/prajjwalyd/analytics:latest ./analytics - docker push docker.io/prajjwalyd/analytics:latest \ No newline at end of file + build_and_push: + needs: test + uses: ./.github/workflows/build_and_push.yml diff --git a/.github/workflows/setup.yml b/.github/workflows/setup.yml new file mode 100644 index 0000000..41a526c --- /dev/null +++ b/.github/workflows/setup.yml @@ -0,0 +1,21 @@ +name: Setup + +on: + workflow_call: + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.22' + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..78cb647 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +name: Test + +on: + workflow_call: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run tests for QR Code Generator + working-directory: qr-code-generator + run: go test -v ./... + + - name: Install pytest + run: pip install flask pytest + + - name: Run tests for URL Shortener + working-directory: url-shortener + run: pytest test_url_shortener.py