|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + test: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + node-version: [22] |
| 15 | + elasticsearch-version: ['8.15.0', '9.0.0'] |
| 16 | + |
| 17 | + name: Node ${{ matrix.node-version }} - ES ${{ matrix.elasticsearch-version }} |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v3 |
| 21 | + |
| 22 | + - name: Use Node.js ${{ matrix.node-version }} |
| 23 | + uses: actions/setup-node@v3 |
| 24 | + with: |
| 25 | + node-version: ${{ matrix.node-version }} |
| 26 | + |
| 27 | + - name: Start Elasticsearch ${{ matrix.elasticsearch-version }} |
| 28 | + run: | |
| 29 | + docker run -d \ |
| 30 | + --name elasticsearch \ |
| 31 | + -p 9200:9200 \ |
| 32 | + -e "discovery.type=single-node" \ |
| 33 | + -e "xpack.security.enabled=false" \ |
| 34 | + -e "xpack.security.enrollment.enabled=false" \ |
| 35 | + docker.elastic.co/elasticsearch/elasticsearch:${{ matrix.elasticsearch-version }} |
| 36 | + |
| 37 | + - name: Wait for Elasticsearch |
| 38 | + run: | |
| 39 | + echo "Waiting for Elasticsearch to be ready..." |
| 40 | + for i in {1..60}; do |
| 41 | + # Check cluster health status |
| 42 | + HEALTH=$(curl -s "http://localhost:9200/_cluster/health" 2>/dev/null || echo "") |
| 43 | + if [ ! -z "$HEALTH" ]; then |
| 44 | + STATUS=$(echo $HEALTH | grep -o '"status":"[^"]*"' | cut -d'"' -f4) |
| 45 | + echo "Attempt $i: Cluster status is '$STATUS'" |
| 46 | + |
| 47 | + # Wait for yellow or green status (yellow is ok for single-node) |
| 48 | + if [ "$STATUS" = "yellow" ] || [ "$STATUS" = "green" ]; then |
| 49 | + echo "Elasticsearch is ready!" |
| 50 | + # Give it a bit more time to fully stabilize |
| 51 | + sleep 5 |
| 52 | + curl -s "http://localhost:9200/_cluster/health?pretty" |
| 53 | + break |
| 54 | + fi |
| 55 | + else |
| 56 | + echo "Attempt $i: Elasticsearch not responding yet..." |
| 57 | + fi |
| 58 | + |
| 59 | + if [ $i -eq 60 ]; then |
| 60 | + echo "ERROR: Elasticsearch failed to become ready after 5 minutes" |
| 61 | + docker logs elasticsearch |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + |
| 65 | + sleep 5 |
| 66 | + done |
| 67 | + |
| 68 | + - name: Install dependencies |
| 69 | + run: npm ci |
| 70 | + |
| 71 | + - name: Build |
| 72 | + run: npm run build |
| 73 | + |
| 74 | + - name: Run tests |
| 75 | + run: | |
| 76 | + ES_VERSION=${{ matrix.elasticsearch-version }} \ |
| 77 | + ELASTICSEARCH_URL=http://localhost:9200 \ |
| 78 | + npm run mocha |
| 79 | + |
| 80 | + release: |
| 81 | + needs: test |
| 82 | + runs-on: ubuntu-latest |
| 83 | + if: github.ref == 'refs/heads/main' |
| 84 | + |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v3 |
| 87 | + with: |
| 88 | + fetch-depth: 0 |
| 89 | + persist-credentials: false |
| 90 | + |
| 91 | + - name: Use Node.js |
| 92 | + uses: actions/setup-node@v3 |
| 93 | + with: |
| 94 | + node-version: 22 |
| 95 | + |
| 96 | + - name: Install dependencies |
| 97 | + run: npm ci |
| 98 | + |
| 99 | + - name: Build |
| 100 | + run: npm run build |
| 101 | + |
| 102 | + - name: Release |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 106 | + run: npx semantic-release |
0 commit comments