feat: add testing job to Docker workflow with Node.js setup #134
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Multi-Platform Docker Image | |
| on: | |
| push: | |
| branches: | |
| - master # Trigger on pushes to the master branch | |
| paths-ignore: | |
| - 'build.txt' # Exclude build.txt from triggering the workflow | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| node-version: [20.x, 22.x, 23.x, 25.x] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Create config file | |
| run: | | |
| if [ ! -f config/config.json ]; then | |
| cp config/config.json.example config/config.json | |
| fi | |
| - name: Run tests | |
| run: npm test | |
| env: | |
| NODE_ENV: test | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: test # Only run if tests pass | |
| steps: | |
| - name: Checkout the repository | |
| uses: actions/checkout@v4.1.7 | |
| - name: Docker Setup QEMU | |
| uses: docker/setup-qemu-action@v3.2.0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3.6.1 | |
| - name: Log in to Docker Hub | |
| run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin | |
| - name: Increment build number | |
| id: build_number | |
| run: | | |
| BUILD_NUMBER=$(cat build.txt) | |
| BUILD_NUMBER=$((BUILD_NUMBER + 1)) | |
| echo $BUILD_NUMBER > build.txt | |
| echo "number=$BUILD_NUMBER" >> $GITHUB_OUTPUT | |
| - name: Build and push multi-platform Docker image | |
| run: | | |
| docker buildx build --platform linux/amd64,linux/arm64 --push \ | |
| -t ${{ secrets.DOCKERHUB_USERNAME }}/slackonos:latest \ | |
| -t ${{ secrets.DOCKERHUB_USERNAME }}/slackonos:build-${{ steps.build_number.outputs.number }} . | |
| - name: Verify the platforms | |
| run: docker buildx inspect --bootstrap | |
| - name: Commit and push updated build.txt | |
| run: | | |
| git config --local user.name "github-actions[bot]" | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git add build.txt | |
| git commit -m "Build ${{ steps.build_number.outputs.number }}" | |
| git push |