Merge pull request #173 from ovotech/BPCPOD-11801-github-actions-pipe… #4
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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| services: | |
| zookeeper: | |
| image: confluentinc/cp-zookeeper:5.0.1 | |
| env: | |
| ZOOKEEPER_CLIENT_PORT: 2181 | |
| ZOOKEEPER_TICK_TIME: 2000 | |
| ports: | |
| - 2181:2181 | |
| kafka: | |
| image: confluentinc/cp-kafka:5.0.1 | |
| env: | |
| KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | |
| KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | |
| KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT | |
| KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092 | |
| ports: | |
| - 9092:9092 | |
| - 29092:29092 | |
| schema-registry: | |
| image: confluentinc/cp-schema-registry:5.0.1 | |
| env: | |
| SCHEMA_REGISTRY_HOST_NAME: schema-registry | |
| SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: zookeeper:2181 | |
| ports: | |
| - 8081:8081 | |
| postgres: | |
| image: circleci/postgres:10-alpine | |
| env: | |
| POSTGRES_PASSWORD: dev-pass | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '12' | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/yarn | |
| key: v1-${{ hashFiles('**/yarn.lock') }} | |
| restore-keys: | | |
| v1- | |
| - name: Configure yarn | |
| run: yarn config set yarn-offline-mirror ~/.cache/yarn | |
| - name: Install dependencies | |
| run: yarn install | |
| - name: Build | |
| run: yarn build | |
| - name: Wait for server | |
| run: .github/workflows/wait-for-server.sh | |
| - name: Test | |
| run: yarn test | |
| prepare-publish: | |
| needs: test | |
| if: github.ref == 'refs/heads/master' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '12' | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/yarn | |
| key: v1-${{ hashFiles('**/yarn.lock') }} | |
| restore-keys: | | |
| v1- | |
| - name: Configure yarn | |
| run: yarn config set yarn-offline-mirror ~/.cache/yarn | |
| - name: Install dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Setup npmrc | |
| run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc | |
| - name: List changed packages | |
| run: yarn lerna exec --concurrency 1 'if [ "$(npm view $LERNA_PACKAGE_NAME version --registry=https://npm.pkg.github.com/ 2>/dev/null || echo "0.0.0")" != "$(node -p "require(\"./package.json\").version")" ]; then echo "Will publish $LERNA_PACKAGE_NAME@$(node -p "require(\"./package.json\").version")"; fi' | |
| publish: | |
| needs: prepare-publish | |
| if: github.ref == 'refs/heads/master' | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-npm-registry | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '12' | |
| - name: Setup npmrc | |
| run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/yarn | |
| key: v1-${{ hashFiles('**/yarn.lock') }} | |
| restore-keys: | | |
| v1- | |
| - name: Configure yarn | |
| run: yarn config set yarn-offline-mirror ~/.cache/yarn | |
| - name: Install dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Build | |
| run: yarn build | |
| - name: Configure Git | |
| run: | | |
| git config user.email "ovotech-ci@ovoenergy.com" | |
| git config user.name "Ovotech CI" | |
| - name: Publish | |
| run: yarn lerna publish from-package --yes --registry https://npm.pkg.github.com | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |