Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 4

Electron-Builder installers for multi platforms

Solved! Go to Solution.

Building an electron app on three platforms. The tool `electron-builder` will produce installers with names like these two for Ubuntu and Windows:

 

- `my-app_1.0.1_amd64.deb`

- `my-app Setup 1.0.1.exe`

 

The version string comes its `package.json`. And I want to run the workflow when I push the tag for `v1.0.1`.

 

I have not been able to figure out a way to set the artifact and asset names to contain the version string (not semver).

 

At the moment, I am hard-coding the version into the workflow itself. Then using action `svenstaro/upload-release-action@v1-release` to upload the tag.

 

Here is the start of the workflow and below that is the uploading action.

```

namebuild and release electron from react web

on:
  push:
    tags:
      - 'v*' # any push with a tag in semver format
    
jobs:
  build:
    namebuild-electron-from-react-web
    env:
      VERSION1.0.1

    # update versions below
    runs-on${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latestwindows-latestmacos-latest]
        include:
          - osubuntu-latest
            artifact_namebook-package-app_1.0.1_amd64.deb
            asset_namebook-package-app_1.0.1_amd64.deb
          - oswindows-latest
            artifact_name"book-package-app Setup 1.0.1.exe"
            asset_name"book-package-app Setup 1.0.1.exe"
```
 
The uploading action:
```
      - nameUpload Release Assets
        usessvenstaro/upload-release-action@v1-release
        env:
          GITHUB_TOKEN${{ secrets.GITHUB_TOKEN }}
        with:
          repo_token${{ secrets.GITHUB_TOKEN }}
          file"./electron/dist/${{ matrix.artifact_name }}"
          asset_name${{ matrix.asset_name }}
          tag${{ github.ref }}
          overwritetrue
```
3 Replies
Highlighted
Solution
GitHub Partner
Message 2 of 4

Re: Electron-Builder installers for multi platforms

Hi @mandolyte ,

 

Thank you for being here!

1. 'Workflow&Job level env' and matrix doesn't accept variables, hence you can set the artifacts/asset name in step level.

2. The version string comes its `package.json`. And I want to run the workflow when I push the tag for `v1.0.1`.

>> You can get the tag version from '${GITHUB_REF##*v}', and compare the value in 'package.json', use if expression to execute the next steps accordingly.

In total, i assume your script can be changed as below(I removed macos part you can add accordingly).

jobs:
  build:
    name: build-electron-from-react-web
#    env:
#      VERSION: 1.0.1

    # update versions below
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
 #       include:
 #         - os: ubuntu-latest
 #           artifact_name: book-package-app_1.0.1_amd64.deb
 #           asset_name: book-package-app_1.0.1_amd64.deb
 #         - os: windows-latest
 #           artifact_name: "book-package-app Setup 1.0.1.exe"
 #          asset_name: "book-package-app Setup 1.0.1.exe"
 
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: set tag version               #If needed, here you can can compare the value form package.json with ${GITHUB_REF##*v}.
        shell: bash
        run: |
          echo "::set-env name=version::${GITHUB_REF##*v}"

      - name: set artifact&asset name for ubuntu
        if: runner.os=='linux'
        run: |
          echo "::set-env name=artifactname::book-package-app_${version}_amd64.deb"
          echo "::set-env name=assetname::book-package-app_${version}_amd64.deb"
      - name: set artifact&asset name for windows
        shell: bash
        if: runner.os=='windows'
        run: |
          echo "::set-env name=artifactname::book-package-app Setup ${version}.exe"
          echo "::set-env name=assetname::book-package-app Setup ${version}.exe"        
      - name: Upload Release Assets
        uses: svenstaro/upload-release-action@v1-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: "./electron/dist/${{ env.artifactname }}"
          asset_name: ${{ env.assetname }}
          tag: ${{ github.ref }}
          overwrite: true

Hope it helps!

 

Highlighted
Copilot Lvl 2
Message 3 of 4

Re: Electron-Builder installers for multi platforms

@weide-zhou 

I think I spoke too soon. Looks like env vars are not allowed where I need them. Hope you have another idea!

 

Annotation 2020-03-26 112754.png

Highlighted
GitHub Partner
Message 4 of 4

Re: Electron-Builder installers for multi platforms

Hi @mandolyte ,

 

Thanks for your reply! The env value to get in action 'with' should use the format : ${{ env.artifactname }}

I have changed in my first post, thanks.

envvalue.png