name: release RC apps

on:
  push:
    branches-ignore:
      - '**'
    # prerelease only
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+-rc[a-f0-9]+.[0-9]+'

jobs:
  push_rc_to_npm:
    name: Push RC module to npm
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2

      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: '14'
          registry-url: 'https://registry.npmjs.org'
          scope: '@chip-in'

      - name: build
        run: |
          npm ci
          npm run clean
          npm run release_build

      - name: release
        run: npm publish --tag prerelease
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

  push_rc_to_dockerhub:
    name: Push Docker RC image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2

      - name: Log in to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v3
        with:
          images: chipin/dadget
          flavor: |
            latest=false
          tags: |
            type=semver,pattern={{version}}
            type=raw,value=latest,enable=false

      - name: Build and push Docker image
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}

  push_server_rc_to_dockerhub:
    name: Push Docker RC image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2

      - name: Log in to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v3
        with:
          images: chipin/rn-mongodb-dadget
          flavor: |
            latest=false
          tags: |
            type=semver,pattern={{version}}
            type=raw,value=latest,enable=false

      - name: Build and push Docker image
        uses: docker/build-push-action@v2
        with:
          context: .
          file: docker-server/Dockerfile
          push: true
          tags: ${{ steps.meta.outputs.tags }}
