Skip to content

Commit

Permalink
🧪 Use prefetched action to make trampoline
Browse files Browse the repository at this point in the history
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 `./`.
  • Loading branch information
webknjaz committed Nov 6, 2024
1 parent 0d02f37 commit fa84826
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 2 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,17 @@ runs:
PR_REF: ${{ github.event.pull_request.head.ref }}
PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
PR_REPO_ID: ${{ github.event.pull_request.base.repo.id }}
- name: Check out action repo
uses: actions/checkout@v4
with:
path: action-repo
ref: ${{ steps.set-repo-and-ref.outputs.ref }}
repository: ${{ steps.set-repo-and-ref.outputs.repo }}
- name: Create Docker container action
run: |
# Create Docker container action
python create-docker-action.py
python ${{ github.action_path }}/create-docker-action.py
env:
REF: ${{ steps.set-repo-and-ref.outputs.ref }}
REPO: ${{ steps.set-repo-and-ref.outputs.repo }}
REPO_ID: ${{ steps.set-repo-and-ref.outputs.repo-id }}
shell: bash
working-directory: action-repo
- name: Run Docker container
uses: ./action-repo/.github/actions/run-docker-container
uses: ./.github/.tmp/.generated-actions/run-pypi-publish-in-docker-container
with:
user: ${{ inputs.user }}
password: ${{ inputs.password }}
Expand Down
9 changes: 7 additions & 2 deletions create-docker-action.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
REPO_ID = os.environ['REPO_ID']
REPO_ID_GH_ACTION = '178055147'

ACTION_SHELL_CHECKOUT_PATH = pathlib.Path(__file__).parent.resolve()


def set_image(ref: str, repo: str, repo_id: str) -> str:
if repo_id == REPO_ID_GH_ACTION:
return '../../../Dockerfile'
return str(ACTION_SHELL_CHECKOUT_PATH / 'Dockerfile')
docker_ref = ref.replace('/', '-')
return f'docker://ghcr.io/{repo}:{docker_ref}'

Expand Down Expand Up @@ -70,6 +72,9 @@ def set_image(ref: str, repo: str, repo_id: str) -> str:
},
}

action_path = pathlib.Path('.github/actions/run-docker-container/action.yml')
action_path = pathlib.Path(
'.github/.tmp/.generated-actions/'
'run-pypi-publish-in-docker-container/action.yml',
)
action_path.parent.mkdir(parents=True, exist_ok=True)
action_path.write_text(json.dumps(action, ensure_ascii=False), encoding='utf-8')

0 comments on commit fa84826

Please sign in to comment.