Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of "env" variables is not correct sometimes #416

Closed
winksaville opened this issue Nov 11, 2020 · 4 comments
Closed

Handling of "env" variables is not correct sometimes #416

winksaville opened this issue Nov 11, 2020 · 4 comments

Comments

@winksaville
Copy link
Contributor

I've created act-failing-python-cache with additional details.

This was tested with act master branch as of 11/10/2020:

$ git log -1
commit 695c4966843d319933d110316032863d138a721b (HEAD -> master, upstream/master, origin/master, origin/HEAD)
Author: Steffen Seckler <38119442+SteffenSeckler@users.noreply.github.com>
Date:   Tue Nov 10 23:55:27 2020 +0100

    Adds ability to use container images from matrices. (#413)
    
    Uses rc.ExprEval.Interpolate on container image.

On a linux computer:

$ inxi -Fxz
System:    Kernel: 5.9.2-arch1-1 x86_64 bits: 64 compiler: N/A Desktop: Cinnamon 4.6.7 Distro: Arch Linux 
Machine:   Type: Desktop Mobo: ASRock model: X570 Creator serial: <filter> UEFI: American Megatrends v: P2.10 date: 12/16/2019 
CPU:       Topology: 12-Core model: AMD Ryzen 9 3900X bits: 64 type: MT MCP arch: Zen 2 L2 cache: 6144 KiB 
           flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 182458 
           Speed: 2196 MHz min/max: 2200/3800 MHz Core speeds (MHz): 1: 2200 2: 2199 3: 3707 4: 2010 5: 2197 6: 2200 7: 2200 
           8: 2195 9: 2201 10: 2198 11: 2198 12: 2199 13: 2200 14: 2196 15: 2109 16: 4080 17: 2098 18: 2199 19: 2199 20: 2200 
           21: 2199 22: 2196 23: 2200 24: 2148 
Graphics:  Device-1: NVIDIA TU116 [GeForce GTX 1660] vendor: Micro-Star MSI driver: nvidia v: 455.38 bus ID: 33:00.0 
           Display: x11 server: X.org 1.20.9 driver: nvidia unloaded: modesetting resolution: <xdpyinfo missing> 
           Message: Unable to show advanced data. Required tool glxinfo missing. 
Audio:     Device-1: NVIDIA TU116 High Definition Audio vendor: Micro-Star MSI driver: snd_hda_intel v: kernel bus ID: 33:00.1 
           Device-2: Advanced Micro Devices [AMD] Starship/Matisse HD Audio vendor: ASRock driver: snd_hda_intel v: kernel 
           bus ID: 35:00.4 
           Sound Server: ALSA v: k5.9.2-arch1-1 
Network:   Device-1: Intel I211 Gigabit Network vendor: ASRock driver: igb v: kernel port: b000 bus ID: 28:00.0 
           IF: enp40s0 state: up speed: 1000 Mbps duplex: full mac: <filter> 
           Device-2: Intel Wi-Fi 6 AX200 driver: iwlwifi v: kernel port: b000 bus ID: 29:00.0 
           IF: wlp41s0 state: down mac: <filter> 
           Device-3: Aquantia AQC107 NBase-T/IEEE 802.3bz Ethernet [AQtion] vendor: ASRock driver: atlantic v: kernel 
           port: a000 bus ID: 2e:00.0 
           IF: enp46s0 state: down mac: <filter> 
           IF-ID-1: docker0 state: down mac: <filter> 
Drives:    Local Storage: total: 465.76 GiB used: 140.26 GiB (30.1%) 
           ID-1: /dev/nvme0n1 vendor: Sabrent model: Rocket 4.0 500GB size: 465.76 GiB 
           ID-2: /dev/nvme1n1 vendor: Sabrent model: Rocket 4.0 500GB size: 465.76 GiB 
Partition: ID-1: / size: 491.15 GiB used: 140.19 GiB (28.5%) fs: ext4 dev: /dev/dm-2 
           ID-2: /boot size: 1.86 GiB used: 73.6 MiB (3.9%) fs: vfat dev: /dev/nvme0n1p1 
Swap:      ID-1: swap-1 type: file size: 512.0 MiB used: 0 KiB (0.0%) file: /swapfile 
Sensors:   System Temperatures: cpu: 47.6 C mobo: N/A 
           Fan Speeds (RPM): N/A 
Info:      Processes: 452 Uptime: 3h 23m Memory: 31.29 GiB used: 4.71 GiB (15.0%) Init: systemd Compilers: gcc: 10.2.0 
           clang: 10.0.1 Shell: bash v: 5.0.18 inxi: 3.1.03 

I was trying to use actions/setup-python@v2 and actions/cache@v2:

$ cat -n .github/workflows/t1.yml
     1	name: t1
     2	
     3	on: [ push, workflow_dispatch ]
     4	
     5	jobs:
     6	  build:
     7	
     8	    name: Linux build and test
     9	    runs-on: ubuntu-latest
    10	    strategy:
    11	      matrix:
    12	        python-version: [3.6]
    13	
    14	    steps:
    15	      - uses: actions/checkout@v2
    16	
    17	      - name: Set up Python ${{ matrix.python-version }}
    18	        uses: actions/setup-python@v2
    19	        with:
    20	          python-version: ${{ matrix.python-version }}
    21	
    22	      #- name: Display env.pythonLocation
    23	      #  run: |
    24	      #    echo env.pythonLocation=${{ env.pythonLocation }}
    25	
    26	      - name: Python cache
    27	        id: python-cache
    28	        uses: actions/cache@v2
    29	        with:
    30	          path: ${{ env.pythonLocation }}
    31	          key: ${{ runner.os }}-python-${{ env.pytnonLocation }}-${{ hashFiles('**/*requirements.txt') }}
    32	          restore-keys: |
    33	            ${{ runner.os }}-python-${{ env.pythonLocation }}
    34	
    35	      - name: Test if cache hit is true
    36	        if: ${{ steps.python-cache.outputs.cache-hit == 'true' }}
    37	        run:  echo steps.python-cache.outputs.cache-hit is true
    38	
    39	      - name: Test if cache hit is not true
    40	        if: ${{ steps.python-cache.outputs.cache-hit != 'true' }}
    41	        run:  echo steps.python-cache.outputs.cache-hit is NOT true
    42	
    43	      - name: Always
    44	        if: ${{ always() }}
    45	        run:  echo Done
    46	
    47	      - name: Done
    48	        run:  echo Done

And Python cache step fails becasue path is empty and "not supplied":

[t1/Linux build and test]   ❗  ::error::Input required and not supplied: path
| (node:67) [DEP0091] DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated.
| (node:67) [DEP0010] DeprecationWarning: crypto.createCredentials is deprecated. Use tls.createSecureContext instead.
| (node:67) [DEP0011] DeprecationWarning: crypto.Credentials is deprecated. Use tls.SecureContext instead.
[t1/Linux build and test]   ❌  Failure - Python cache
Error: exit with `FAILURE`: 1

The full log:

wink@3900x:~/prgs/python/projects/hw (main)
$ ~/prgs/nektos/forks/act/dist/local/act
[t1/Linux build and test] 🧪  Matrix: map[python-version:3.6]
[t1/Linux build and test] 🚀  Start image=winksaville/ubuntu-dev:20.04
[t1/Linux build and test]   🐳  docker run image=winksaville/ubuntu-dev:20.04 entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[t1/Linux build and test]   🐳  docker cp src=/home/wink/prgs/python/projects/hw/. dst=/github/workspace
[t1/Linux build and test] ⭐  Run actions/checkout@v2
[t1/Linux build and test]   ✅  Success - actions/checkout@v2
[t1/Linux build and test] ⭐  Run Set up Python ${{ matrix.python-version }}
[t1/Linux build and test]   ☁  git clone 'https://github.com/actions/setup-python' # ref=v2
[t1/Linux build and test]   🐳  docker cp src=/home/wink/.cache/act/actions-setup-python@v2 dst=/actions/
[t1/Linux build and test]   💬  ::debug::Semantic version spec of 3.6 is 3.6
[t1/Linux build and test]   💬  ::debug::isExplicit: 
[t1/Linux build and test]   💬  ::debug::explicit? false
[t1/Linux build and test]   💬  ::debug::evaluating 0 versions
[t1/Linux build and test]   💬  ::debug::match not found
| Version 3.6 was not found in the local cache
[t1/Linux build and test]   💬  ::debug::check 3.10.0-alpha.2 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.10.0-alpha.1 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.9.0 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.9.0-rc.2 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.9.0-rc.1 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.9.0-beta.5 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.9.0-beta.4 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.8.6 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.8.5 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.8.4 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.8.3 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.8.2 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.8.1 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.8.0 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.7.9 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.7.8 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.7.7 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.7.6 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.7.5 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::check 3.6.12 satisfies 3.6
[t1/Linux build and test]   💬  ::debug::x64===x64 && darwin===linux
[t1/Linux build and test]   💬  ::debug::x64===x64 && linux===linux
[t1/Linux build and test]   💬  ::debug::x64===x64 && linux===linux
[t1/Linux build and test]   💬  ::debug::x64===x64 && linux===linux
[t1/Linux build and test]   💬  ::debug::matched 3.6.12
| Version 3.6 is available for downloading
| Download from "https://github.com/actions/python-versions/releases/download/3.6.12-86954/python-3.6.12-linux-20.04-x64.tar.gz"
[t1/Linux build and test]   💬  ::debug::Downloading https://github.com/actions/python-versions/releases/download/3.6.12-86954/python-3.6.12-linux-20.04-x64.tar.gz
[t1/Linux build and test]   💬  ::debug::Destination /tmp/bd1c11b3-37ac-401d-aeb2-c64739f2e2d4
[t1/Linux build and test]   💬  ::debug::download complete
| Extract downloaded archive
[t1/Linux build and test]   💬  ::debug::Checking tar --version
[t1/Linux build and test]   💬  ::debug::tar (GNU tar) 1.30%0ACopyright (C) 2017 Free Software Foundation, Inc.%0ALicense GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.%0AThis is free software: you are free to change and redistribute it.%0AThere is NO WARRANTY, to the extent permitted by law.%0A%0AWritten by John Gilmore and Jay Fenlason.
| [command]/usr/bin/tar xz --warning=no-unknown-keyword -C /tmp/3f36a6e7-53ff-4b90-a4c2-287eaa444487 -f /tmp/bd1c11b3-37ac-401d-aeb2-c64739f2e2d4
| Execute installation script
| Check if Python hostedtoolcache folder exist...
| Creating Python hostedtoolcache folder...
| Create Python 3.6.12 folder
| Copy Python binaries to hostedtoolcache folder
| Create additional symlinks (Required for the UsePythonVersion Azure Pipelines task and the setup-python GitHub Action)
| Upgrading PIP...
| Looking in links: /tmp/tmpdhmeux8q
| Requirement already satisfied: setuptools in /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages (40.6.2)
| Requirement already satisfied: pip in /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages (18.1)
| Collecting pip
| Downloading https://files.pythonhosted.org/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl (1.5MB)
| Installing collected packages: pip
| Successfully installed pip-20.2.4
[t1/Linux build and test]   ❗  ::error::You are using pip version 20.2.4, however version 20.3b1 is available.%0AYou should consider upgrading via the 'pip install --upgrade pip' command.
| Create complete file
[t1/Linux build and test]   💬  ::debug::isExplicit: 
[t1/Linux build and test]   💬  ::debug::explicit? false
[t1/Linux build and test]   💬  ::debug::isExplicit: 3.6.12
[t1/Linux build and test]   💬  ::debug::explicit? true
[t1/Linux build and test]   💬  ::debug::evaluating 1 versions
[t1/Linux build and test]   💬  ::debug::matched: 3.6.12
[t1/Linux build and test]   💬  ::debug::checking cache: /opt/hostedtoolcache/Python/3.6.12/x64
[t1/Linux build and test]   💬  ::debug::Found tool in cache Python 3.6.12 x64
[t1/Linux build and test]   ⚙  ::set-env:: pythonLocation=/opt/hostedtoolcache/Python/3.6.12/x64
[t1/Linux build and test]   ⚙  ::set-env:: LD_LIBRARY_PATH=/opt/hostedtoolcache/Python/3.6.12/x64/lib
[t1/Linux build and test]   ⚙  ::add-path:: /opt/hostedtoolcache/Python/3.6.12/x64
[t1/Linux build and test]   ⚙  ::add-path:: /opt/hostedtoolcache/Python/3.6.12/x64/bin
[t1/Linux build and test]   ⚙  ::set-output:: python-version=3.6.12
| Successfully setup CPython (3.6.12)
[t1/Linux build and test]   ❓  ##[add-matcher]/actions/actions-setup-python@v2/.github/python.json
[t1/Linux build and test]   ✅  Success - Set up Python ${{ matrix.python-version }}
[t1/Linux build and test] ⭐  Run Python cache
[t1/Linux build and test]   ☁  git clone 'https://github.com/actions/cache' # ref=v2
[t1/Linux build and test]   🐳  docker cp src=/home/wink/.cache/act/actions-cache@v2 dst=/actions/
[t1/Linux build and test]   ❓  ::save-state name=CACHE_KEY::Linux-python--e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
[t1/Linux build and test]   ❗  ::error::Input required and not supplied: path
| (node:67) [DEP0091] DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated.
| (node:67) [DEP0010] DeprecationWarning: crypto.createCredentials is deprecated. Use tls.createSecureContext instead.
| (node:67) [DEP0011] DeprecationWarning: crypto.Credentials is deprecated. Use tls.SecureContext instead.
[t1/Linux build and test]   ❌  Failure - Python cache
Error: exit with `FAILURE`: 1

As it so happens while creating the test case I found a hack to that solves the problem.
If you add a step between Set up Python and Python cache that displays env.pythonLocation
(i.e. uncomment lines 22-24 of t1.yml above):

      - name: Display env.pythonLocation
        run: |
          echo env.pythonLocation=${{ env.pythonLocation }}

Then act can complete all steps:

  1	$ ~/prgs/nektos/forks/act/dist/local/act
  2	[t1/Linux build and test] 🧪  Matrix: map[python-version:3.6]
  3	[t1/Linux build and test] 🚀  Start image=winksaville/ubuntu-dev:20.04
  4	[t1/Linux build and test]   🐳  docker run image=winksaville/ubuntu-dev:20.04 entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
  5	[t1/Linux build and test]   🐳  docker cp src=/home/wink/prgs/python/projects/hw/. dst=/github/workspace
  6	[t1/Linux build and test] ⭐  Run actions/checkout@v2
  7	[t1/Linux build and test]   ✅  Success - actions/checkout@v2
  8	[t1/Linux build and test] ⭐  Run Set up Python ${{ matrix.python-version }}
  9	[t1/Linux build and test]   ☁  git clone 'https://github.com/actions/setup-python' # ref=v2
 10	[t1/Linux build and test]   🐳  docker cp src=/home/wink/.cache/act/actions-setup-python@v2 dst=/actions/
 11	[t1/Linux build and test]   💬  ::debug::Semantic version spec of 3.6 is 3.6
 12	[t1/Linux build and test]   💬  ::debug::isExplicit: 
 13	[t1/Linux build and test]   💬  ::debug::explicit? false
 14	[t1/Linux build and test]   💬  ::debug::evaluating 0 versions
 15	[t1/Linux build and test]   💬  ::debug::match not found
 16	| Version 3.6 was not found in the local cache
 17	[t1/Linux build and test]   💬  ::debug::check 3.10.0-alpha.2 satisfies 3.6
 18	[t1/Linux build and test]   💬  ::debug::check 3.10.0-alpha.1 satisfies 3.6
 19	[t1/Linux build and test]   💬  ::debug::check 3.9.0 satisfies 3.6
 20	[t1/Linux build and test]   💬  ::debug::check 3.9.0-rc.2 satisfies 3.6
 21	[t1/Linux build and test]   💬  ::debug::check 3.9.0-rc.1 satisfies 3.6
 22	[t1/Linux build and test]   💬  ::debug::check 3.9.0-beta.5 satisfies 3.6
 23	[t1/Linux build and test]   💬  ::debug::check 3.9.0-beta.4 satisfies 3.6
 24	[t1/Linux build and test]   💬  ::debug::check 3.8.6 satisfies 3.6
 25	[t1/Linux build and test]   💬  ::debug::check 3.8.5 satisfies 3.6
 26	[t1/Linux build and test]   💬  ::debug::check 3.8.4 satisfies 3.6
 27	[t1/Linux build and test]   💬  ::debug::check 3.8.3 satisfies 3.6
 28	[t1/Linux build and test]   💬  ::debug::check 3.8.2 satisfies 3.6
 29	[t1/Linux build and test]   💬  ::debug::check 3.8.1 satisfies 3.6
 30	[t1/Linux build and test]   💬  ::debug::check 3.8.0 satisfies 3.6
 31	[t1/Linux build and test]   💬  ::debug::check 3.7.9 satisfies 3.6
 32	[t1/Linux build and test]   💬  ::debug::check 3.7.8 satisfies 3.6
 33	[t1/Linux build and test]   💬  ::debug::check 3.7.7 satisfies 3.6
 34	[t1/Linux build and test]   💬  ::debug::check 3.7.6 satisfies 3.6
 35	[t1/Linux build and test]   💬  ::debug::check 3.7.5 satisfies 3.6
 36	[t1/Linux build and test]   💬  ::debug::check 3.6.12 satisfies 3.6
 37	[t1/Linux build and test]   💬  ::debug::x64===x64 && darwin===linux
 38	[t1/Linux build and test]   💬  ::debug::x64===x64 && linux===linux
 39	[t1/Linux build and test]   💬  ::debug::x64===x64 && linux===linux
 40	[t1/Linux build and test]   💬  ::debug::x64===x64 && linux===linux
 41	[t1/Linux build and test]   💬  ::debug::matched 3.6.12
 42	| Version 3.6 is available for downloading
 43	| Download from "https://github.com/actions/python-versions/releases/download/3.6.12-86954/python-3.6.12-linux-20.04-x64.tar.gz"
 44	[t1/Linux build and test]   💬  ::debug::Downloading https://github.com/actions/python-versions/releases/download/3.6.12-86954/python-3.6.12-linux-20.04-x64.tar.gz
 45	[t1/Linux build and test]   💬  ::debug::Destination /tmp/c495d26e-cc71-42d0-9493-19511dab5bd0
 46	[t1/Linux build and test]   💬  ::debug::download complete
 47	| Extract downloaded archive
 48	[t1/Linux build and test]   💬  ::debug::Checking tar --version
 49	[t1/Linux build and test]   💬  ::debug::tar (GNU tar) 1.30%0ACopyright (C) 2017 Free Software Foundation, Inc.%0ALicense GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.%0AThis is free software: you are free to change and redistribute it.%0AThere is NO WARRANTY, to the extent permitted by law.%0A%0AWritten by John Gilmore and Jay Fenlason.
 50	| [command]/usr/bin/tar xz --warning=no-unknown-keyword -C /tmp/29f48a50-fedc-4db0-bb3e-5c181150eacf -f /tmp/c495d26e-cc71-42d0-9493-19511dab5bd0
 51	| Execute installation script
 52	| Check if Python hostedtoolcache folder exist...
 53	| Creating Python hostedtoolcache folder...
 54	| Create Python 3.6.12 folder
 55	| Copy Python binaries to hostedtoolcache folder
 56	| Create additional symlinks (Required for the UsePythonVersion Azure Pipelines task and the setup-python GitHub Action)
 57	| Upgrading PIP...
 58	| Looking in links: /tmp/tmp5bged5zx
 59	| Requirement already satisfied: setuptools in /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages (40.6.2)
 60	| Requirement already satisfied: pip in /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages (18.1)
 61	| Collecting pip
 62	| Downloading https://files.pythonhosted.org/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl (1.5MB)
 63	| Installing collected packages: pip
 64	| Successfully installed pip-20.2.4
 65	[t1/Linux build and test]   ❗  ::error::You are using pip version 20.2.4, however version 20.3b1 is available.%0AYou should consider upgrading via the 'pip install --upgrade pip' command.
 66	| Create complete file
 67	[t1/Linux build and test]   💬  ::debug::isExplicit: 
 68	[t1/Linux build and test]   💬  ::debug::explicit? false
 69	[t1/Linux build and test]   💬  ::debug::isExplicit: 3.6.12
 70	[t1/Linux build and test]   💬  ::debug::explicit? true
 71	[t1/Linux build and test]   💬  ::debug::evaluating 1 versions
 72	[t1/Linux build and test]   💬  ::debug::matched: 3.6.12
 73	[t1/Linux build and test]   💬  ::debug::checking cache: /opt/hostedtoolcache/Python/3.6.12/x64
 74	[t1/Linux build and test]   💬  ::debug::Found tool in cache Python 3.6.12 x64
 75	[t1/Linux build and test]   ⚙  ::set-env:: pythonLocation=/opt/hostedtoolcache/Python/3.6.12/x64
 76	[t1/Linux build and test]   ⚙  ::set-env:: LD_LIBRARY_PATH=/opt/hostedtoolcache/Python/3.6.12/x64/lib
 77	[t1/Linux build and test]   ⚙  ::add-path:: /opt/hostedtoolcache/Python/3.6.12/x64
 78	[t1/Linux build and test]   ⚙  ::add-path:: /opt/hostedtoolcache/Python/3.6.12/x64/bin
 79	[t1/Linux build and test]   ⚙  ::set-output:: python-version=3.6.12
 80	| Successfully setup CPython (3.6.12)
 81	[t1/Linux build and test]   ❓  ##[add-matcher]/actions/actions-setup-python@v2/.github/python.json
 82	[t1/Linux build and test]   ✅  Success - Set up Python ${{ matrix.python-version }}
 83	[t1/Linux build and test] ⭐  Run Display env.pythonLocation
 84	| env.pythonLocation=/opt/hostedtoolcache/Python/3.6.12/x64
 85	[t1/Linux build and test]   ✅  Success - Display env.pythonLocation
 86	[t1/Linux build and test] ⭐  Run Python cache
 87	[t1/Linux build and test]   ☁  git clone 'https://github.com/actions/cache' # ref=v2
 88	[t1/Linux build and test]   🐳  docker cp src=/home/wink/.cache/act/actions-cache@v2 dst=/actions/
 89	[t1/Linux build and test]   ❓  ::save-state name=CACHE_KEY::Linux-python--e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
 90	[t1/Linux build and test]   💬  ::debug::Resolved Keys:
 91	[t1/Linux build and test]   💬  ::debug::["Linux-python--e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","Linux-python-/opt/hostedtoolcache/Python/3.6.12/x64"]
 92	[t1/Linux build and test]   💬  ::debug::Checking zstd --version
 93	| (node:72) [DEP0091] DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated.
 94	| (node:72) [DEP0010] DeprecationWarning: crypto.createCredentials is deprecated. Use tls.createSecureContext instead.
 95	| (node:72) [DEP0011] DeprecationWarning: crypto.Credentials is deprecated. Use tls.SecureContext instead.
 96	[t1/Linux build and test]   💬  ::debug::Unable to locate executable file: zstd. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
 97	[t1/Linux build and test]   💬  ::debug::
 98	[t1/Linux build and test]   💬  ::debug::getCacheEntry - Attempt 1 of 2 failed with error: Cache Service Url not found, unable to restore cache.
 99	[t1/Linux build and test]   💬  ::debug::getCacheEntry - Attempt 2 of 2 failed with error: Cache Service Url not found, unable to restore cache.
100	| [warning]getCacheEntry failed: Cache Service Url not found, unable to restore cache.
101	[t1/Linux build and test]   ⚙  ::set-output:: cache-hit=false
102	[t1/Linux build and test]   ✅  Success - Python cache
103	[t1/Linux build and test] ⭐  Run Test if cache hit is not true
104	| steps.python-cache.outputs.cache-hit is NOT true
105	[t1/Linux build and test]   ✅  Success - Test if cache hit is not true
106	[t1/Linux build and test] ⭐  Run Always
107	| Done
108	[t1/Linux build and test]   ✅  Success - Always
109	[t1/Linux build and test] ⭐  Run Done
110	| Done
111	[t1/Linux build and test]   ✅  Success - Done
@winksaville
Copy link
Contributor Author

In act-failing-python-cache workaround branch is t1.yml with the extra step added.

@winksaville winksaville mentioned this issue Nov 12, 2020
@torbjornvatn
Copy link
Contributor

torbjornvatn commented Nov 13, 2020

Added a comment to your question about this issue here: #417 (comment)

@winksaville
Copy link
Contributor Author

My diagnosis of the problem is that when a new step is created and newStepExecutor is invoked, see below. It setups a new environ with _ = sc.setupEnv()(ctx) which "inherits" the environment from the previous step and then creates an expression evaluator for the new step with rc.ExprEval = sc.NewExpressionEvaluator():

func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
	sc := &StepContext{
		RunContext: rc,
		Step:       step,
	}
	return func(ctx context.Context) error {
		rc.CurrentStep = sc.Step.ID
		rc.StepResults[rc.CurrentStep] = &stepResult{
			Success: true,
			Outputs: make(map[string]string),
		}

		_ = sc.setupEnv()(ctx)
		rc.ExprEval = sc.NewExpressionEvaluator()

		if !rc.EvalBool(sc.Step.If) {
			log.Debugf("Skipping step '%s' due to '%s'", sc.Step.String(), sc.Step.If)
			return nil
		}

		common.Logger(ctx).Infof("\u2B50  Run %s", sc.Step)
		err := sc.Executor()(ctx)
		if err == nil {
			common.Logger(ctx).Infof("  \u2705  Success - %s", sc.Step)
		} else {
			common.Logger(ctx).Errorf("  \u274C  Failure - %s", sc.Step)
			rc.StepResults[rc.CurrentStep].Success = false
		}
		return err
	}
}

This is fine but there is a problem, in setupEnv it loops through all of the environment variables interpolating any ${{ xxxx }} into "concrete" values:

		for k, v := range env {
			env[k] = rc.ExprEval.Interpolate(v)
		}

But notice that setupEnv uses rc.ExprEval which is the evaluator for the previous step that was created before the previous step was executed. Therefore the rc.ExprEval being used does not contain any env values from the previous step itself, but only values from "its previous step". Therefore, if the "new step" references environment variables that were created or updated in the just completed step they will be empty or old values.

Here is the full code for func setupEnv:

func (sc *StepContext) setupEnv() common.Executor {
	rc := sc.RunContext
	job := rc.Run.Job()
	step := sc.Step
	return func(ctx context.Context) error {
		var env map[string]string
		c := job.Container()
		if c != nil {
			env = mergeMaps(rc.GetEnv(), c.Env, step.GetEnv())
		} else {
			env = mergeMaps(rc.GetEnv(), step.GetEnv())
		}

		if (rc.ExtraPath != nil) && (len(rc.ExtraPath) > 0) {
			s := append(rc.ExtraPath, os.Getenv("PATH"))
			env["PATH"] = strings.Join(s, string(os.PathListSeparator))
		}

		for k, v := range env {
			env[k] = rc.ExprEval.Interpolate(v)
		}
		sc.Env = rc.withGithubEnv(env)
		log.Debugf("setupEnv => %v", sc.Env)
		return nil
	}
}

My solution is to call setupEnv and NewExpressionEvaluator a second time. The first invocation will update the enviornemt variables and then rc.ExprEval set and its enviornemt will now be "complete", the second invocation will then have the complete set of environment variables and in my case env.pythonLocation will have the correct value after the second invocations. The diff is at this comment to #419.

I suspect there is a "better" solution, I'll see if I can work something up,

winksaville added a commit to winksaville/act that referenced this issue Nov 16, 2020
This is a solution to issue nektos#416 where environment variables created or
changed in the previous step are not usable in the next step because
the rc.ExprEval is from the beginning of the previous step.

This change refactors setupEnv so that before interpolating the environment
variables a NewExpressionEvaluator is created.

Fixes: 416
winksaville added a commit to winksaville/act that referenced this issue Nov 17, 2020
This is a solution to issue nektos#416 where environment variables created or
changed in the previous step are not usable in the next step because
the rc.ExprEval is from the beginning of the previous step.

This change refactors setupEnv so that before interpolating the environment
variables a NewExpressionEvaluator is created.

Fixes: 416
winksaville added a commit to winksaville/act that referenced this issue Nov 17, 2020
Test issue nektos#416. With PR nektos#423 the test passes and fails otherwise.

To facilitate this new test I refactored RunTestJobFile out of
TestRunEvent and use it in TestRunEvent and TestPythonCache
winksaville added a commit to winksaville/act that referenced this issue Nov 18, 2020
This is a solution to issue nektos#416 where environment variables created or
changed in the previous step are not usable in the next step because
the rc.ExprEval is from the beginning of the previous step.

This change refactors setupEnv so that before interpolating the environment
variables a NewExpressionEvaluator is created.

Fixes: 416
winksaville added a commit to winksaville/act that referenced this issue Nov 18, 2020
Test issue nektos#416. With PR nektos#423 the test passes and fails otherwise.

To facilitate this new test I refactored RunTestJobFile out of
TestRunEvent and use it in TestRunEvent and TestPythonCache
winksaville added a commit to winksaville/act that referenced this issue Nov 22, 2020
This is a solution to issue nektos#416 where environment variables created or
changed in the previous step are not usable in the next step because
the rc.ExprEval is from the beginning of the previous step.

This change refactors setupEnv so that before interpolating the environment
variables a NewExpressionEvaluator is created.

Add TestSetEnvVar which specifically tests that issue 416 is fixed.
As it turns out the problem manifests itself with javascript based
but not docker based actions. TestSenEnvVar test both docker and
js actions that set environment variables.

Fixes: 416
winksaville added a commit to winksaville/act that referenced this issue Nov 30, 2020
This is a solution to issue nektos#416 where environment variables created or
changed in the previous step are not usable in the next step because
the rc.ExprEval is from the beginning of the previous step.

This change refactors setupEnv so that before interpolating the environment
variables a NewExpressionEvaluator is created.

Add TestSetEnvVar which specifically tests that issue 416 is fixed.
As it turns out the problem manifests itself with javascript based
but not docker based actions. TestSenEnvVar test both docker and
js actions that set environment variables.

Fixes: 416
winksaville added a commit to winksaville/act that referenced this issue Jan 12, 2021
This is a solution to issue nektos#416 where environment variables created or
changed in the previous step are not usable in the next step because
the rc.ExprEval is from the beginning of the previous step.

This change refactors setupEnv so that before interpolating the environment
variables a NewExpressionEvaluator is created.


Fixes: 416
winksaville added a commit to winksaville/act that referenced this issue Jan 12, 2021
This is a solution to issue nektos#416 where environment variables created or
changed in the previous step are not usable in the next step because
the rc.ExprEval is from the beginning of the previous step.

This change refactors setupEnv so that before interpolating the environment
variables a NewExpressionEvaluator is created.


Fixes: 416
cplee pushed a commit that referenced this issue Jan 13, 2021
This is a solution to issue #416 where environment variables created or
changed in the previous step are not usable in the next step because
the rc.ExprEval is from the beginning of the previous step.

This change refactors setupEnv so that before interpolating the environment
variables a NewExpressionEvaluator is created.


Fixes: 416
@winksaville
Copy link
Contributor Author

Fix with #423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants