[PR #1732] [MERGED] fix: environment handling windows (host mode) #2100

Closed
opened 2026-03-01 21:54:00 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/nektos/act/pull/1732
Author: @ChristopherHX
Created: 4/16/2023
Status: Merged
Merged: 4/18/2023
Merged by: @mergify[bot]

Base: masterHead: fix-env-handling-windows-host-mode


📝 Commits (10+)

📊 Changes

12 files changed (+107 additions, -17 deletions)

View changed files

📝 pkg/container/executions_environment.go (+2 -0)
📝 pkg/container/host_environment.go (+4 -0)
📝 pkg/container/linux_container_environment_extensions.go (+4 -0)
📝 pkg/runner/action.go (+2 -2)
📝 pkg/runner/action_composite.go (+8 -6)
📝 pkg/runner/command.go (+9 -3)
📝 pkg/runner/run_context.go (+9 -0)
📝 pkg/runner/step.go (+33 -5)
📝 pkg/runner/step_test.go (+3 -1)
pkg/runner/testdata/windows-add-env/action.yml (+7 -0)
📝 pkg/runner/testdata/windows-add-env/push.yml (+17 -0)
📝 pkg/runner/testdata/windows-prepend-path/push.yml (+9 -0)

📄 Description

Why?

Currently we merge env variables with case sensitive key, this is problematic on windows where PATH and Path are the same key.

Other Changes considered:
Create a custom env type

type Map[K comparable, V any] interface {
	Set(key K, val V)
	Get(key K) V
	TryGet(key K) (V, bool)
	AsNative() map[K]V
}

type CaseInsensitiveMap[V any] struct {
	lookUp map[string]string
	Native map[string]V
}

func (m *CaseInsensitiveMap[V]) getKey(key string) string {
	return strings.Map(func(r rune) rune {
		for {
			next := unicode.SimpleFold(r)
			if next <= r {
				return r
			}
			r = next
		}
	}, key)
}

func (m *CaseInsensitiveMap[V]) Set(key string, val V) {
	foldkey := m.getKey(key)
	if m.Native == nil {
		m.Native = map[string]V{}
	}
	if fk, ok := m.lookUp[foldkey]; ok {
		m.Native[fk] = val
	} else {
		if m.lookUp == nil {
			m.lookUp = map[string]string{}
		}
		m.lookUp[foldkey] = key
		m.Native[key] = val
	}
}

func (m *CaseInsensitiveMap[V]) Get(key string) V {
	v, _ := m.TryGet(key)
	return v
}

func (m *CaseInsensitiveMap[V]) TryGet(key string) (V, bool) {
	foldkey := m.getKey(key)
	if m.Native == nil {
		m.Native = map[string]V{}
	}
	if fk, ok := m.lookUp[foldkey]; ok {
		return m.Native[fk], true
	}
	return m.Native[key], false
}

func (m *CaseInsensitiveMap[V]) AsNative() map[string]V {
	return m.Native
}

type RegularMap[K comparable, V any] struct {
	Native map[K]V
}

func (m *RegularMap[K, V]) Set(key K, val V) {
	if m.Native == nil {
		m.Native = map[K]V{}
	}
	m.Native[key] = val
}

func (m *RegularMap[K, V]) Get(key K) V {
	return m.Native[key]
}

func (m *RegularMap[K, V]) TryGet(key K) (V, bool) {
	v, ok := m.Native[key]
	return v, ok
}

func (m *RegularMap[K, V]) AsNative() map[K]V {
	return m.Native
}

However this would require a lot of changes across the codebase.

Next steps:

  • make the env expressions context case sensitive again for non windows, because the env keys can be duplucated in the map

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/nektos/act/pull/1732 **Author:** [@ChristopherHX](https://github.com/ChristopherHX) **Created:** 4/16/2023 **Status:** ✅ Merged **Merged:** 4/18/2023 **Merged by:** [@mergify[bot]](https://github.com/apps/mergify) **Base:** `master` ← **Head:** `fix-env-handling-windows-host-mode` --- ### 📝 Commits (10+) - [`43c6bae`](https://github.com/nektos/act/commit/43c6baed0e267a84af3e68c2fd41b5c8d3b966d9) fix: environment handling windows (host mode) - [`c08607a`](https://github.com/nektos/act/commit/c08607a020be0f8471da8c4f0b2f289535f21161) fixup - [`b3337d0`](https://github.com/nektos/act/commit/b3337d07689d766f5564851b540279349f95a083) fixup - [`eb0e5ad`](https://github.com/nektos/act/commit/eb0e5adb944d160b6efd6e98f8e0f6293fb7530e) add more tests - [`7c16ade`](https://github.com/nektos/act/commit/7c16ade1210076ac1d863aaed7dd8f52c2316a54) fixup - [`6af0356`](https://github.com/nektos/act/commit/6af0356543f35705a424bce8cb1a9aab25bce1cb) fix setenv - [`fb99651`](https://github.com/nektos/act/commit/fb996511b1a3983d51bc532cd4cf0629d106cf65) fixes - [`4b94919`](https://github.com/nektos/act/commit/4b94919cb7d5517755c2c22f3eced84b6060fa3b) [skip ci] Apply suggestions from code review - [`699a768`](https://github.com/nektos/act/commit/699a7680ea0940792faf4556d9bb6529fe8c5e63) Update side effects - [`1a8244a`](https://github.com/nektos/act/commit/1a8244ab5ff8a4f3cc3b350349e8ea96b5978357) Merge branch 'master' into fix-env-handling-windows-host-mode ### 📊 Changes **12 files changed** (+107 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `pkg/container/executions_environment.go` (+2 -0) 📝 `pkg/container/host_environment.go` (+4 -0) 📝 `pkg/container/linux_container_environment_extensions.go` (+4 -0) 📝 `pkg/runner/action.go` (+2 -2) 📝 `pkg/runner/action_composite.go` (+8 -6) 📝 `pkg/runner/command.go` (+9 -3) 📝 `pkg/runner/run_context.go` (+9 -0) 📝 `pkg/runner/step.go` (+33 -5) 📝 `pkg/runner/step_test.go` (+3 -1) ➕ `pkg/runner/testdata/windows-add-env/action.yml` (+7 -0) 📝 `pkg/runner/testdata/windows-add-env/push.yml` (+17 -0) 📝 `pkg/runner/testdata/windows-prepend-path/push.yml` (+9 -0) </details> ### 📄 Description Why? Currently we merge env variables with case sensitive key, this is problematic on windows where PATH and Path are the same key. Other Changes considered: Create a custom env type ```go type Map[K comparable, V any] interface { Set(key K, val V) Get(key K) V TryGet(key K) (V, bool) AsNative() map[K]V } type CaseInsensitiveMap[V any] struct { lookUp map[string]string Native map[string]V } func (m *CaseInsensitiveMap[V]) getKey(key string) string { return strings.Map(func(r rune) rune { for { next := unicode.SimpleFold(r) if next <= r { return r } r = next } }, key) } func (m *CaseInsensitiveMap[V]) Set(key string, val V) { foldkey := m.getKey(key) if m.Native == nil { m.Native = map[string]V{} } if fk, ok := m.lookUp[foldkey]; ok { m.Native[fk] = val } else { if m.lookUp == nil { m.lookUp = map[string]string{} } m.lookUp[foldkey] = key m.Native[key] = val } } func (m *CaseInsensitiveMap[V]) Get(key string) V { v, _ := m.TryGet(key) return v } func (m *CaseInsensitiveMap[V]) TryGet(key string) (V, bool) { foldkey := m.getKey(key) if m.Native == nil { m.Native = map[string]V{} } if fk, ok := m.lookUp[foldkey]; ok { return m.Native[fk], true } return m.Native[key], false } func (m *CaseInsensitiveMap[V]) AsNative() map[string]V { return m.Native } type RegularMap[K comparable, V any] struct { Native map[K]V } func (m *RegularMap[K, V]) Set(key K, val V) { if m.Native == nil { m.Native = map[K]V{} } m.Native[key] = val } func (m *RegularMap[K, V]) Get(key K) V { return m.Native[key] } func (m *RegularMap[K, V]) TryGet(key K) (V, bool) { v, ok := m.Native[key] return v, ok } func (m *RegularMap[K, V]) AsNative() map[K]V { return m.Native } ``` However this would require a lot of changes across the codebase. Next steps: - make the `env` expressions context case sensitive again for non windows, because the env keys can be duplucated in the map --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-01 21:54:00 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#2100
No description provided.