name: Release

on:
  workflow_dispatch:
    inputs:
      release_type:
        description: 'Final release or beta'
        required: true
        type: choice
        options:
        - final
        - beta

jobs:
  release:
    if: github.repository == 'moodlemobile/moodleapp'
    runs-on: ubuntu-latest
    env:
      RELEASE_TYPE: ${{ github.event.inputs.release_type || 'final' }}

    steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false
        fetch-depth: 0
    - uses: actions/setup-node@v3
      with:
        node-version-file: '.nvmrc'
    - name: Install npm packages
      run: npm ci --no-audit
    - name: Create release tags
      env:
        GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
      run: ./.github/scripts/release.sh $RELEASE_TYPE