How do I make a file "executable" in github actions?

633 views Asked by At

I build a little command-line tool using python, and have been trying to use Github Actions to build it for the various different platforms. To build the project into a standalone binary, I am using the Nuitka Action, and then I'm releasing it using the Github Release. The relevant parts of the .yml file looks like this:

  - name: Build python script into a stand-alone binary (ubuntu)
    if: startsWith(matrix.os, 'ubuntu')
    uses: Nuitka/Nuitka-Action@main
    with:
      working-directory: src
      nuitka-version: main
      script-name: directory/main.py
      onefile: true
      output-file: main.bin

  - name: Make binary executable
    run: chmod +x ./src/build/main.bin

  - name: Upload Artifact
    uses: actions/upload-artifact@v3
    with:
      name: ${{ matrix.os }} build
      path: src/build/main.bin

  - name: Release
    uses: softprops/action-gh-release@v1
    with:
      files: src/build/main.bin

When I push the appropriate tag, the correct action gets triggered, and it creates a Release, builds my binary and attaches it.

The issue is that the file I download from the release is not marked as executable. I literally need to locally chmod +x the file I've downloaded, otherwise it opens and looks like this:

A screenshot of the file internals that looks like corrupted data

You can see that I've tried adding a "Make binary executable step" but this doesn't seem to fix my issue. How do I force my file to remember it's supposed to be an executable upon download?

1

There are 1 answers

0
sytech On

The executable bit (as set by chmod +x) is filesystem information and not contained in the contents of the file itself. It does not change the file in any particular way. Same goes for other information like owner, last modified date, etc -- it's not part of the file contents.

Hence, if you upload the file outside of your filesystem and download it elsewhere, it won't have any of the filesystem information like the executable bit from the source computer. It's just the file.

If you archive your file using something like tar, you can capture that filesystem information as part of the archive and then upload the archive containing the executable instead of the executable file itself. Then when you download and extract the file from the archive, you can choose to keep the original permissions or other filesystem information contained in the archive.

TL;DR: archive your file first to a .tar file then upload it and later extract it preserving permissions.