name: Android
on:
  release:
    types: [published]

jobs:
  build-android:
    runs-on: ubuntu-latest
    container: ghcr.io/jandedobbeleer/golang-android-container:latest
    steps:
    - name: Checkout code 👋
      uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
    - name: Build
      run: |
        VERSION=$(echo "${{ github.event.release.name }}" | cut -c2-)
        echo "Building version ${VERSION}"
        cd src
        go build -o dist/posh-android-arm -ldflags="-s -w -X 'github.com/jandedobbeleer/oh-my-posh/src/build.Version=${VERSION}' -X 'github.com/jandedobbeleer/oh-my-posh/src/build.Date=$(date)'"
    - name: Upload artifacts 🆙
      uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
      with:
        github-token: ${{secrets.GITHUB_TOKEN}}
        script: |
          console.log('environment', process.versions);

          const fs = require('fs').promises;

          const { repo: { owner, repo }, sha } = context;
          console.log({ owner, repo, sha });

          await github.rest.repos.uploadReleaseAsset({
            owner, repo,
            release_id: ${{ github.event.release.id }},
            name: 'posh-android-arm',
            data: await fs.readFile('./src/dist/posh-android-arm')
          });
