---
name: Release
on:
  push:
    tags:
    - "**jedi**"

env:
  IMAGE_BASE: docker.pkg.github.com/${{ github.repository }}
  GITHUB_TOKEN: ${{ secrets.GitHub_PAT }}
  PACKAGE_REPO_GIT: https://ultimaker-package:${{ secrets.GitHub_PAT }}@github.com/Ultimaker/jedi-package-repository.git
  PACKAGE_REPO_BRANCH: "master master-next_som"
  GIT_AUTHOR_NAME: embedded
  GIT_AUTHOR_EMAIL: embedded@ultimaker.com
  GIT_COMMITTER_NAME: embedded
  GIT_COMMITTER_EMAIL: embedded@ultimaker.com
  EMAIL: embedded@ultimaker.com

stages:
  - validate

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
      with:
        submodules: true # 'recursive' 'true' or 'false'
        token: ${{ secrets.GitHub_PAT }} # `GitHub_PAT` is a secret contains your PAT.

    - run: echo "${GITHUB_TOKEN}" | docker login -u fdm_materials-c3po --password-stdin docker.pkg.github.com
    - run: docker run -i -u "$(id -u)" -v "$(pwd):/source" --rm -e CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=/usr -DEMBEDDED=ON" registry.gitlab.com/ultimaker/stardust/print-cluster-jedi-scripts/print-cluster-jedi-scripts-cmake:latest

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

    - name: Upload artifacts
      uses: actions/upload-artifact@v1
      with:
        name: "fdm_materials-${{ steps.get_version.outputs.VERSION }}_all"
        path: "./fdm_materials-${{ steps.get_version.outputs.VERSION }}_all.deb"

    - run: docker run -i -u "$(id -u)" -v "$(pwd):/source" --rm -e PACKAGE_REPO_GIT -e PACKAGE_REPO_BRANCH -e RELEASE_VERSION="${GITHUB_REF/refs\/tags\//}" -e GIT_AUTHOR_NAME -e GIT_AUTHOR_EMAIL -e GIT_COMMITTER_NAME -e GIT_COMMITTER_EMAIL -e EMAIL -e ARTIFACT_PATH="/source/fdm_materials-${{ steps.get_version.outputs.VERSION }}_all" registry.gitlab.com/ultimaker/stardust/print-cluster-jedi-scripts/print-cluster-jedi-scripts-cmake:latest /push_artifacts.sh
