diff --git a/.github/actions/github/action.yml b/.github/actions/github/action.yml new file mode 100644 index 0000000..b6fa18b --- /dev/null +++ b/.github/actions/github/action.yml @@ -0,0 +1,31 @@ +name: 'Docker Container Action' +description: 'A reimplementation of docker container action' +inputs: + github: + description: 'The GitHub context' + required: true + default: ${{ toJSON(github) }} +outputs: + action_repository: + description: 'The GitHub action repository name' + value: ${{ steps.action.outputs.action_repository }} + action_ref: + description: 'The GitHub action repository ref' + value: ${{ steps.action.outputs.action_ref }} +runs: + using: 'composite' + steps: + - id: action + env: + ACTION_PATH: ${{ fromJSON(inputs.github).action_path }} + REPOSITORY: ${{ fromJSON(inputs.github).repository }} + SHA: ${{ fromJSON(inputs.github).sha }} + run: | + if [[ $ACTION_PATH == */_actions/* ]]; then + echo "action_repository=$(echo ${ACTION_PATH#*/_actions/} | cut -d/ -f1-2)" >> $GITHUB_OUTPUT + echo "action_ref=$(echo ${ACTION_PATH#*/_actions/} | cut -d/ -f3)" >> $GITHUB_OUTPUT + else + echo "action_repository=$GITHUB_REPOSITORY" >> $GITHUB_OUTPUT + echo "action_ref=$GITHUB_SHA" >> $GITHUB_OUTPUT + fi + shell: bash diff --git a/CHANGELOG.md b/CHANGELOG.md index 6165ecf..695961e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## [1.1.3] - 2023-03-10 +### Added +- Added `.github/actions/github` composite action to infer GitHub action repository and ref from GitHub action path + ## [1.1.2] - 2023-03-10 ### Changed - Do not pass internal inputs to the docker run step diff --git a/README.md b/README.md index 92f470f..a02e329 100644 --- a/README.md +++ b/README.md @@ -42,22 +42,14 @@ When the Docker Container Action runs, it first checks if the specified image ex 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: ```yml -# This step is required because GitHub Actions doesn't set GITHUB_ACTION_REPOSITORY nor GITHUB_ACTION_REF properly :( -- id: action - run: | - if [[ $GITHUB_ACTION_PATH == */_actions/* ]]; then - echo "repository=$(echo ${GITHUB_ACTION_PATH#*/_actions/} | cut -d/ -f1-2)" >> $GITHUB_OUTPUT - echo "ref=$(echo ${GITHUB_ACTION_PATH#*/_actions/} | cut -d/ -f3)" >> $GITHUB_OUTPUT - else - echo "repository=$GITHUB_REPOSITORY" >> $GITHUB_OUTPUT - echo "ref=$GITHUB_SHA" >> $GITHUB_OUTPUT - fi - shell: bash +- id: github + name: Infer GitHub action repository and ref from GitHub action path + uses: pl-strflt/docker-container-action/.github/actions/github@v1 - name: Run Docker container uses: pl-strflt/docker-container-action@v1 with: - repository: ${{ env.GITHUB_ACTION_REPOSITORY }} - ref: ${{ env.GITHUB_ACTION_REF }} + repository: ${{ steps.github.outputs.action_repository }} + ref: ${{ steps.github.outputs.action_ref }} opts: --network=host ```