Skip to content

Commit dfcfeca

Browse files
committed
🧪 Use prefetched action to make trampoline
Previously, the action repository was being cloned from the remote twice, unnecessarily. This patch eliminates this step and uses the copy that was checked out on job start. The generated trampoline action is still copied into the allowlisted working directory so it can be referenced by the relative path starting with `./`. It is now output under `./.github/.tmp/.generated-actions/run-pypi-publish-in-docker-container` which mutates the end-user's workspace slightly but uses a path that is unlikely to clash with somebody else's use. Unfortunately, we cannot use randomized paths because the composite action syntax does not allow accessing variables in `uses:`. Fixes #292.
1 parent 0d02f37 commit dfcfeca

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

action.yml

+13-9
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,28 @@ runs:
130130
PR_REF: ${{ github.event.pull_request.head.ref }}
131131
PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
132132
PR_REPO_ID: ${{ github.event.pull_request.base.repo.id }}
133-
- name: Check out action repo
134-
uses: actions/checkout@v4
135-
with:
136-
path: action-repo
137-
ref: ${{ steps.set-repo-and-ref.outputs.ref }}
138-
repository: ${{ steps.set-repo-and-ref.outputs.repo }}
139133
- name: Create Docker container action
140134
run: |
141135
# Create Docker container action
142-
python create-docker-action.py
136+
python ${{ github.action_path }}/create-docker-action.py
143137
env:
144138
REF: ${{ steps.set-repo-and-ref.outputs.ref }}
145139
REPO: ${{ steps.set-repo-and-ref.outputs.repo }}
146140
REPO_ID: ${{ steps.set-repo-and-ref.outputs.repo-id }}
147141
shell: bash
148-
working-directory: action-repo
149142
- name: Run Docker container
150-
uses: ./action-repo/.github/actions/run-docker-container
143+
# The generated trampoline action must exist in the allowlisted
144+
# runner-defined working directory so it can be referenced by the
145+
# relative path starting with `./`.
146+
#
147+
# This mutates the end-user's workspace slightly but uses a path
148+
# that is unlikely to clash with somebody else's use.
149+
#
150+
# We cannot use randomized paths because the composite action
151+
# syntax does not allow accessing variables in `uses:`. This
152+
# means that we end up having to hardcode this path both here and
153+
# in `create-docker-action.py`.
154+
uses: ./.github/.tmp/.generated-actions/run-pypi-publish-in-docker-container
151155
with:
152156
user: ${{ inputs.user }}
153157
password: ${{ inputs.password }}

create-docker-action.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
REPO_ID = os.environ['REPO_ID']
1111
REPO_ID_GH_ACTION = '178055147'
1212

13+
ACTION_SHELL_CHECKOUT_PATH = pathlib.Path(__file__).parent.resolve()
14+
1315

1416
def set_image(ref: str, repo: str, repo_id: str) -> str:
1517
if repo_id == REPO_ID_GH_ACTION:
16-
return '../../../Dockerfile'
18+
return str(ACTION_SHELL_CHECKOUT_PATH / 'Dockerfile')
1719
docker_ref = ref.replace('/', '-')
1820
return f'docker://ghcr.io/{repo}:{docker_ref}'
1921

@@ -70,6 +72,20 @@ def set_image(ref: str, repo: str, repo_id: str) -> str:
7072
},
7173
}
7274

73-
action_path = pathlib.Path('.github/actions/run-docker-container/action.yml')
75+
# The generated trampoline action must exist in the allowlisted
76+
# runner-defined working directory so it can be referenced by the
77+
# relative path starting with `./`.
78+
#
79+
# This mutates the end-user's workspace slightly but uses a path
80+
# that is unlikely to clash with somebody else's use.
81+
#
82+
# We cannot use randomized paths because the composite action
83+
# syntax does not allow accessing variables in `uses:`. This
84+
# means that we end up having to hardcode this path both here and
85+
# in `action.yml`.
86+
action_path = pathlib.Path(
87+
'.github/.tmp/.generated-actions/'
88+
'run-pypi-publish-in-docker-container/action.yml',
89+
)
7490
action_path.parent.mkdir(parents=True, exist_ok=True)
7591
action_path.write_text(json.dumps(action, ensure_ascii=False), encoding='utf-8')

0 commit comments

Comments
 (0)