diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..4c53acc --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,45 @@ +name: Publish Docker image + +on: + release: + types: [published] + +jobs: + push_to_registries: + name: Push Docker image + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: | + jarrodback/highway-tracker + ghcr.io/${{ github.repository }} + + - name: Build and push Docker images + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: ./server/ + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 30bfc55..bcb5927 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -4,56 +4,129 @@ name: Build-Test-Deploy Pipeline on: - push + workflow_dispatch: + pull_request: + push: jobs: build: - runs-on: ubuntu-latest strategy: matrix: node-version: [16.x] - mongodb-version: [4.2] steps: - uses: actions/checkout@v2 - - name: Start MongoDB v${{ matrix.mongodb-version }} - uses: supercharge/mongodb-github-action@1.2.0 - with: - mongodb-version: ${{ matrix.mongodb-version }} + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} cache: 'npm' cache-dependency-path: server/package-lock.json + - name: Server - run build run: | cd server npm ci npm run build --if-present + - name: UI - run build run: | cd ui npm ci npm run build --if-present - - name: Server - run tests + + - uses: actions/upload-artifact@master + with: + name: build-ui + path: | + ui + !ui/node_modules + + - uses: actions/upload-artifact@master + with: + name: build-server + path: | + server + !server/node_modules + + test-ui: + runs-on: ubuntu-latest + needs: [build] + + steps: + - uses: actions/download-artifact@master + with: + name: build-ui + + - name: UI - run tests run: | - cd server + npm i npm test - - name: UI - run tests + + test-server: + runs-on: ubuntu-latest + needs: [build] + + strategy: + matrix: + mongodb-version: [4.2] + + steps: + - name: Start MongoDB v${{ matrix.mongodb-version }} + uses: supercharge/mongodb-github-action@1.2.0 + with: + mongodb-version: ${{ matrix.mongodb-version }} + + - uses: actions/download-artifact@master + with: + name: build-server + + - name: Server - run tests run: | - cd ui + npm i npm test + + - uses: actions/upload-artifact@master + with: + name: coverage-server + path: | + coverage + + coverage: + runs-on: ubuntu-latest + needs: [test-server,test-ui] + + if: >- + github.event_name == 'pull_request' + steps: + - uses: actions/download-artifact@master + with: + name: coverage-server + - name: Code Coverage - if: github.event_name == 'pull_request' - uses: romeovs/lcov-reporter-action@v0.2.16 + uses: romeovs/lcov-reporter-action@v0.3.1 with: - lcov-file: ./server/coverage/lcov.info + lcov-file: lcov.info github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Deploy + + deploy: + runs-on: ubuntu-latest + needs: [test-server,test-ui] + + if: >- + github.event_name == 'pull_request' + steps: + - uses: actions/checkout@v2 + + - uses: actions/download-artifact@master + with: + name: build-ui + + - name: Deploy to GitHub Pages uses: JamesIves/github-pages-deploy-action@v4.2.3 with: branch: gh-pages - folder: ./ui/dist/ + folder: dist