---
name: Container with all prod providers
on: 
  workflow_dispatch:
    inputs:
     tag:
      description: 'Tag in semver format'
      required: true

jobs:
  container_prod_all_providers:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2 # Checking out the repo
      - name: Build and Publish Docker image
        uses: VaultVulp/gp-docker-action@1.2.0
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          image-name: vmpooler
          build-context: ./docker/prod-all-providers/
          dockerfile: ./docker/prod-all-providers/Dockerfile
          image-tag: ${{ github.event.inputs.tag }}-prod-all-providers
      - name: Generate Release Body
        env:
          RELEASE_BODY_FILE: "${{ github.event.inputs.tag }}-prod-all-providers-release-body.md"
        run: |
          echo "## Components" > ${RELEASE_BODY_FILE}
          echo "" >> ${RELEASE_BODY_FILE}
          echo "This release includes the following:" >> ${RELEASE_BODY_FILE}
          echo "" >> ${RELEASE_BODY_FILE}
          echo "### Source image" >> ${RELEASE_BODY_FILE}
          echo "" >> ${RELEASE_BODY_FILE}
          echo "- $(grep ^FROM ./docker/prod-all-providers/Dockerfile |cut -d ' ' -f2) + OS updates" >> ${RELEASE_BODY_FILE}
          echo "" >> ${RELEASE_BODY_FILE}
          echo "### Gems" >> ${RELEASE_BODY_FILE}
          echo "" >> ${RELEASE_BODY_FILE}
          echo "$(grep -e 'vmpooler ([0-9]' docker/prod-all-providers/Gemfile.lock | xargs -L1 echo -)" >> ${RELEASE_BODY_FILE}
          echo "$(grep -e 'vmpooler-provider-.* ([0-9]' docker/prod-all-providers/Gemfile.lock | xargs -L1 echo -)" >> ${RELEASE_BODY_FILE}
      - name: Tag Release
        uses: ncipollo/release-action@v1
        with:
          tag: ${{ github.event.inputs.tag }}-prod-all-providers
          token: ${{ secrets.GITHUB_TOKEN }}
          draft: false
          prerelease: false
          bodyFile: ${{ github.event.inputs.tag }}-prod-all-providers-release-body.md
          generateReleaseNotes: true