samuelmeuli / action-electron-builder

:electron: GitHub Action for building and releasing Electron apps
MIT License
658 stars 201 forks source link

release doesn't exist and not created because "publish" is not "always" and build is not on tag tag #65

Closed Piyush-Use-Personal closed 3 years ago

Piyush-Use-Personal commented 3 years ago

HELP WANTED!

Hey thanks for reaching to this issue

I am building an electron app that uses ReactJS, sqlite3, and sequelizer as the main area.

I have been new in the GitHub action and I tried making an action that will trigger on 2 occasions for my electron app

  1. When a release has been made
  2. When a push on the testing branch

I wanted to generate artifacts for both of the occasions but something is not adding up

I have tried everything which the action-electron-builder actions say but it keeps on saying *release doesn't exist and not created because "publish" is not "always" and build is not on tag v.*.*** without any error

The repo is private and I cannot share much project level info tho but attaching an action result for ref image

This is my GitHub workflow file

name: Build/release

on:
  push:
    branches:
      - main
env:
  CI: false

jobs:
  release:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        # os: [macos-latest, ubuntu-latest, windows-latest]
        os: [ubuntu-latest]

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v1

      - name: Install Node.js, NPM and Yarn
        uses: actions/setup-node@v1
        with:
          node-version: 14

      - name: Build/release Electron app
        uses: samuelmeuli/action-electron-builder@v1
        with:
          # GitHub token, automatically provided to the action
          # (No need to define this secret in the repo settings)
          github_token: ${{ secrets.github_token }}

          # If the commit is tagged with a version (e.g. "v1.0.0"),
          # release the app after building
          release: ${{ startsWith(github.ref, 'refs/tags/v') }}

And this is my package.json

{
  "name": "app-name",
  "version": "0.1.4",
  "private": true,
  "main": "public/main.js",
  "homepage": "./",
  "author": "Some author",
  "repository": {
    "type": "git",
    "url": "some link"
  },
  "dependencies": {
    "@ant-design/charts": "^1.1.3",
    "@ant-design/icons": "^4.6.2",
    "@electron/remote": "^1.1.0",
    "@reduxjs/toolkit": "^1.5.1",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "antd": "^4.15.4",
    "axios": "^0.21.1",
    "bcrypt": "^5.0.1",
    "concurrently": "^6.0.2",
    "cross-env": "^7.0.3",
    "dotenv": "^8.2.0",
    "electron-is-dev": "^2.0.0",
    "moment": "^2.29.1",
    "node-sass": "^5.0.0",
    "platform-folders": "^0.5.3",
    "prop-types": "^15.7.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.3",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "react-to-print": "^2.12.4",
    "redux-logger": "^3.0.6",
    "redux-saga": "^1.1.3",
    "sequelize": "^6.6.2",
    "sqlite3": "^5.0.2",
    "styled-components": "^5.2.3",
    "umzug": "^2.3.0",
    "wait-on": "^5.3.0",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "release": "electron-builder",
    "pack": "electron-builder --dir",
    "dist": "electron-builder",
    "electron:serve": "concurrently -k \"cross-env BROWSER=none yarn start\" \"yarn electron:start\"",
    "electron:build": "yarn build && electron-builder -c.extraMetadata.main=build/main.js",
    "package": "yarn electron:build --publish=always",
    "electron:start": "wait-on tcp:3000 && electron .",
    "postinstall": "electron-builder install-app-deps",
    "migration:create": "sequelize-cli migration:create --name",
    "migration:up": "sequelize db:migrate",
    "migration:down": "sequelize db:migrate:undo",
    "migration:down:all": "sequelize db:migrate:undo:all",
    "seeder:create": "sequelize seed:generate --name",
    "seeder:up": "sequelize db:seed:all",
    "seeder:down": "sequelize db:seed:undo",
    "seeder:down:all": "sequelize db:seed:undo:all"
  },
  "build": {
    "productName": "some product",
    "extends": null,
    "appId": "com.appId",
    "directories": {
      "buildResources": "assets"
    }
  },
  "publish": [
    {
      "provider": "github",
      "owner": "owner-name",
      "repo": "repo-link"
    }
  ],
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "electron": "^12.0.5",
    "electron-builder": "^22.10.5",
    "eslint": "^7.24.0",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-prettier": "^8.2.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-prettier": "^3.4.0",
    "eslint-plugin-react": "^7.23.2",
    "eslint-plugin-react-hooks": "^4.2.0",
    "prettier": "^2.2.1"
  }
}

Please let me know in case I'm doing some horrible mistakes

scope2229 commented 3 years ago

I recently experienced this and it was due to not bring authenticated with snap. Once I added

"Linux": { "target": "AppImage"}

It prevented snapcraft from being created and removed the issues.

scope2229 commented 3 years ago

If this doesn't help at the very bottom of your action change the release value to true instead of the check for a tag. If you want to only build on tags change the on: method to activated on main that has tags

Piyush-Use-Personal commented 3 years ago

@scope2229 Can you give some reference in the package.json file or if you could edit the same package.json? I am kind of stuck with every trial and error Now I'm getting this error snapcraft is not installed, please: sudo snap install snapcraft --classic Added that line in package.json


  "Linux": {
    "target": "AppImage"
  }
scope2229 commented 3 years ago

I took a deeper look at your package.json file looks like your "build" is setup with some errors.

 "build": {
    "productName": "some product",
    "extends": null,
    "appId": "com.appId",
    "directories": {
      "buildResources": "assets"
    }
  },
  "publish": [
    {
      "provider": "github",
      "owner": "owner-name",
      "repo": "repo-link"
    }
  ],

A basic Electron builder configuration would look something like this.

"build": {
    "appId": "io.companyname.appname",
    "productName": "appname",
    "files": [
      "dist/**/*.{js,css,html,ttf}"
    ],
    "directories": {
      "buildResources": "./"
    },
    "mac": {
      "category": "public.app-category.developer-tools",
      "icon": "icons/icon.icns",
      "artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
      "hardenedRuntime": true,
      "entitlementsInherit": "build/entitlements.mac.inherit-plist"
    },
    "linux": {
      "target": "AppImage",
      "artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
      "icon": "icons/icon.png",
      "category": "Development"
    },
    "win": {
      "target": "nsis",
      "artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
      "icon": "icons/icon.png"
    },
    "publish": {
      "provider": "github",
      "repo": "reponame",
      "owner": "ownername",
      "releaseType": "release"
    },
    "afterSign": "./build/afterSignHook.js"
  },

Your publish needs to be inside "build", along with "mac", "win", "linux" all lower case. Publish you only really need an array if your going to publish to multiple repo's or locations. Example Github and S3. If you need the configuration options for each you can get them from the Electron builder docs

Also to answer your other questions

name: Build/release

on:
  push:
    branches:
      - main

env:
  CI: false

jobs:
  release:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        # os: [macos-latest, ubuntu-latest, windows-latest]
        os: [ubuntu-latest]

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v1

      - name: Install Node.js, NPM and Yarn
        uses: actions/setup-node@v1
        with:
          node-version: 14

      - name: Build/release Electron app
        uses: samuelmeuli/action-electron-builder@v1
        with:
          # GitHub token, automatically provided to the action
          # (No need to define this secret in the repo settings)
          github_token: ${{ secrets.github_token }}

          # If the commit is tagged with a version (e.g. "v1.0.0"),
          # release the app after building
          release: ${{ startsWith(github.ref, 'refs/tags/v') }}

I would have this run only when i push a tag. For testing you would be better off building locally on your machine without using a github action.

on:
  push:
    tags:
      # Build on every tag in the form v1.2.3-something.4
      - 'v*'

macos-latest should be macOs-latest

github_token: ${{ secrets.github_token }} make sure to change this to a name your using and store the value in settings/secrets, either i did something wrong or it just wouldn't automatically get the token, also if you release to a public repo form a private you'll need to set this anyway.

release: ${{ startsWith(github.ref, 'refs/tags/v') }} this doesn't work you'll need to update it to the correct function or just set to true. (setting to true is the easiest option as this will only run on a tag being pushed).

Piyush-Use-Personal commented 3 years ago

@scope2229 I'm using exact same conf as your with addition to

    "extends": null,
    "files": [
      "dist/**/*",
      "package.json"
    ],

and Now it is giving me this error

Error: Application entry file "build/main.js" in the "<path>/dist/mac/<app-name>/Contents/Resources/app.asar" does not exist.
hcmlopes commented 3 years ago

The issue here is actually with the github action file. By default it will run the script electron-builder this does not mean it will by default create the release if it doesn't exist. to do this you have to include the args: "-p always" which will then make sure a new release is created even if no draft release exists

Here is my currently working example

# This is a basic workflow to help you get started with Actions

name: Build/release

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches:
      - master

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  release:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [windows-latest, macos-latest]

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      - name: Install Node.js, NPM and Yarn
        uses: actions/setup-node@v1
        with:
          node-version: 14

      - name: Build/release Electron app
        uses: samuelmeuli/action-electron-builder@v1
        with:
          # GitHub token, automatically provided to the action
          # (No need to define this secret in the repo settings)
          github_token: ${{ secrets.github_token }}
          use_vue_cli: true
          args: "-p always"

          # If the commit is tagged with a version (e.g. "v1.0.0"),
          # release the app after building
          release: ${{ startsWith(github.ref, 'refs/tags/v') }}
Piyush-Use-Personal commented 3 years ago

@hcmlopes Still getting same error

Piyush-Use-Personal commented 3 years ago

The other issues got fixed, I just need to remove the files array and it is working as fine. Thanks a lot @scope2229 and @hcmlopes

But now it is failing for GITHUB_TOKEN. Even after using the separate variable for this. Any idea how to fix that?

scope2229 commented 3 years ago

Don't call GitHub tokens GitHub have it like GH_TOKEN. GitHub prevents secrets starting with GitHub. To expand on @hcmlopes he's correct although missed the fact the release is described inside the build configuration in your package.json. so pick one not both.

Piyush-Use-Personal commented 3 years ago

Don't call GitHub tokens GitHub have it like GH_TOKEN. GitHub prevents secrets starting with GitHub. To expand on @hcmlopes he's correct although missed the fact the release is described inside the build configuration in your package.json. so pick one not both.

Are you saying I need to remove the public object from package.json ? On the other note, I have updated the variable to OWN_REPO_TOKEN but still gives the same error

Edit: It was a typo for me

Piyush-Use-Personal commented 3 years ago

Guys @hcmlopes @scope2229 Thanks for your support and I'm closing this issue now. The only additional thing I have to do is remove the files object from package.json.

scope2229 commented 3 years ago

So it could be

github_token: ${{ secrets.GH_TOKEN }}

Then in your GitHub secrets name it GH_TOKEN

electrovir commented 3 years ago

@scope2229

release: ${{ startsWith(github.ref, 'refs/tags/v') }} this doesn't work you'll need to update it to the correct function or just set to true. (setting to true is the easiest option as this will only run on a tag being pushed).

How do we figure out what the "correct function" is and how to call it?

scope2229 commented 3 years ago

You would need to check GitHub docs and find the ref object for tags. But honestly I feel it's better to only run the action if a tag is created and pushed.

Then you can simply use release: true for the action to release and false for a draft.