name: Release

on:
  push:
    tags:
    - '*'

jobs:
  docker:
    name: Docker image
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.4.0
        with:
          repository: YOURLS/docker
          ref: main

      - name: Get the version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

      - name: Set published version
        run: echo "${{ steps.get_version.outputs.VERSION }}" > yourls_version

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3.11.0
        with:
          token: ${{ secrets.PAT }}
          commit-message: Bump YOURLS to ${{ steps.get_version.outputs.VERSION }}
          title: Bump YOURLS to ${{ steps.get_version.outputs.VERSION }}
          delete-branch: true

  charts:
    name: Helm charts
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.4.0
        with:
          repository: YOURLS/charts
          ref: main

      - name: Get the version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

      - name: Set published version
        run: |
          sed -i "s/appVersion:.*/appVersion: \"${{ steps.get_version.outputs.VERSION }}\"/" charts/yourls/Chart.yaml

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3.11.0
        with:
          token: ${{ secrets.PAT }}
          commit-message: Bump YOURLS to ${{ steps.get_version.outputs.VERSION }}
          title: Bump YOURLS to ${{ steps.get_version.outputs.VERSION }}
          delete-branch: true
          draft: true
