From af8163541ac54df6bd71267458d5c2329da41605 Mon Sep 17 00:00:00 2001 From: Wolvan Date: Fri, 4 Feb 2022 21:24:11 +0100 Subject: [PATCH] Add tests and automatic image publishing A couple of github action files have been added that (hopefully) run tests and CI for the docker images on push to dev and master. --- .dockerignore | 1 + .github/dependabot.yml | 7 +++ .github/workflows/docker-image-dev.yml | 51 ++++++++++++++++++++++ .github/workflows/docker-image-master.yml | 52 +++++++++++++++++++++++ .github/workflows/run-tests.yml | 28 ++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/docker-image-dev.yml create mode 100644 .github/workflows/docker-image-master.yml create mode 100644 .github/workflows/run-tests.yml diff --git a/.dockerignore b/.dockerignore index fcbedbd..4ac4521 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ **/.dockerignore **/.env **/.git +**/.github **/.gitignore **/.project **/.settings diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..583decf --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" \ No newline at end of file diff --git a/.github/workflows/docker-image-dev.yml b/.github/workflows/docker-image-dev.yml new file mode 100644 index 0000000..ad405a4 --- /dev/null +++ b/.github/workflows/docker-image-dev.yml @@ -0,0 +1,51 @@ +name: Docker Dev Image CI + +on: + push: + branches: [ dev ] + +jobs: + test: + runs-on: ubuntu-latest + steps: + # Checkout the Repo + - uses: actions/checkout@v2 + + # Install Node 16 + - name: Setup Node + uses: actions/setup-node@v1 + with: + node-version: 16 + + # Avoid running prepublish script + - run: npm set-script prepublish "" + + # Install dependencies + - run: npm install + + # Run tests + - run: npm test + + build: + needs: test + runs-on: ubuntu-latest + + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + push: true + tags: wolvan/poll.horse:dev diff --git a/.github/workflows/docker-image-master.yml b/.github/workflows/docker-image-master.yml new file mode 100644 index 0000000..8970496 --- /dev/null +++ b/.github/workflows/docker-image-master.yml @@ -0,0 +1,52 @@ +name: Docker Image CI + +on: + push: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + steps: + # Checkout the Repo + - uses: actions/checkout@v2 + + # Install Node 16 + - name: Setup Node + uses: actions/setup-node@v1 + with: + node-version: 16 + + # Avoid running prepublish script + - run: npm set-script prepublish "" + + # Install dependencies + - run: npm install + + # Run tests + - run: npm test + + build: + if: startsWith(github.event.ref, 'refs/tags') + needs: test + runs-on: ubuntu-latest + + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + push: true + tags: wolvan/poll.horse:latest diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..8eb5306 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,28 @@ +name: Run tests + +on: + push: + branches: [ dev, master ] + pull_request: + branches: [ dev ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 14.x, 15.x, 16.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm set-script prepublish "" + - run: npm ci + - run: npm run build --if-present + - run: npm test \ No newline at end of file