Merge pull request #175 from ovotech/BPCPOD-11801-cleanup #11
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@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '12' | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| 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 | |
| outputs: | |
| has_changes: ${{ steps.check_changes.outputs.has_changes }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '12' | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| 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 | |
| id: check_changes | |
| run: | | |
| echo "### Following pending deployments found" >> $GITHUB_STEP_SUMMARY | |
| OUTPUT=$(yarn lerna exec --loglevel silent --concurrency 1 -- \ | |
| 'VERSION=$(node -p "require(\"./package.json\").version"); \ | |
| if [ "$(npm view $LERNA_PACKAGE_NAME version --registry=https://npm.pkg.github.com/ 2>/dev/null || echo "0.0.0")" != "$VERSION" ]; then \ | |
| echo "- **$LERNA_PACKAGE_NAME** - will publish version $VERSION"; \ | |
| fi' | grep '\- \*\*' || true) | |
| if [ -n "$OUTPUT" ]; then | |
| echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| echo "- None" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| publish: | |
| needs: prepare-publish | |
| if: github.ref == 'refs/heads/master' && needs.prepare-publish.outputs.has_changes == 'true' | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-npm-registry | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '12' | |
| - name: Setup npmrc | |
| run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| 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 }} |