Skip to content

Commit ccf3d39

Browse files
committed
feat: add .github/actions/github
1 parent 200ee9a commit ccf3d39

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

.github/actions/github/action.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'Docker Container Action'
2+
description: 'A reimplementation of docker container action'
3+
inputs:
4+
github:
5+
description: 'The GitHub context'
6+
required: true
7+
default: ${{ toJSON(github) }}
8+
outputs:
9+
action_repository:
10+
description: 'The GitHub action repository name'
11+
value: ${{ steps.action.outputs.action_repository }}
12+
action_ref:
13+
description: 'The GitHub action repository ref'
14+
value: ${{ steps.action.outputs.action_ref }}
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- id: action
19+
env:
20+
ACTION_PATH: ${{ fromJSON(inputs.github).action_path }}
21+
REPOSITORY: ${{ fromJSON(inputs.github).repository }}
22+
SHA: ${{ fromJSON(inputs.github).sha }}
23+
run: |
24+
if [[ $ACTION_PATH == */_actions/* ]]; then
25+
echo "action_repository=$(echo ${ACTION_PATH#*/_actions/} | cut -d/ -f1-2)" >> $GITHUB_OUTPUT
26+
echo "action_ref=$(echo ${ACTION_PATH#*/_actions/} | cut -d/ -f3)" >> $GITHUB_OUTPUT
27+
else
28+
echo "action_repository=$GITHUB_REPOSITORY" >> $GITHUB_OUTPUT
29+
echo "action_ref=$GITHUB_SHA" >> $GITHUB_OUTPUT
30+
fi
31+
shell: bash

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
## [1.1.3] - 2023-03-10
10+
### Added
11+
- Added `.github/actions/github` composite action to infer GitHub action repository and ref from GitHub action path
12+
913
## [1.1.2] - 2023-03-10
1014
### Changed
1115
- Do not pass internal inputs to the docker run step

README.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,14 @@ When the Docker Container Action runs, it first checks if the specified image ex
4242
This action is commonly used inside a composite action. For example, if the composite action is defined in the `github/example` repository, you could use the Docker Container Action in a step with the following syntax:
4343

4444
```yml
45-
# This step is required because GitHub Actions doesn't set GITHUB_ACTION_REPOSITORY nor GITHUB_ACTION_REF properly :(
46-
- id: action
47-
run: |
48-
if [[ $GITHUB_ACTION_PATH == */_actions/* ]]; then
49-
echo "repository=$(echo ${GITHUB_ACTION_PATH#*/_actions/} | cut -d/ -f1-2)" >> $GITHUB_OUTPUT
50-
echo "ref=$(echo ${GITHUB_ACTION_PATH#*/_actions/} | cut -d/ -f3)" >> $GITHUB_OUTPUT
51-
else
52-
echo "repository=$GITHUB_REPOSITORY" >> $GITHUB_OUTPUT
53-
echo "ref=$GITHUB_SHA" >> $GITHUB_OUTPUT
54-
fi
55-
shell: bash
45+
- id: github
46+
name: Infer GitHub action repository and ref from GitHub action path
47+
uses: pl-strflt/docker-container-action/.github/actions/github@v1
5648
- name: Run Docker container
5749
uses: pl-strflt/docker-container-action@v1
5850
with:
59-
repository: ${{ env.GITHUB_ACTION_REPOSITORY }}
60-
ref: ${{ env.GITHUB_ACTION_REF }}
51+
repository: ${{ steps.github.outputs.action_repository }}
52+
ref: ${{ steps.github.outputs.action_ref }}
6153
opts: --network=host
6254
```
6355

0 commit comments

Comments
 (0)