Skip to content

Commit d970249

Browse files
committed
first commit
0 parents  commit d970249

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/reusable.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Reusable
2+
on:
3+
workflow_call:
4+
outputs:
5+
ref:
6+
description: 'The ref the reusable workflow was called with.'
7+
value: ${{ jobs.reusable.outputs.ref }}
8+
sha:
9+
description: 'The sha the reusable workflow was called with.'
10+
value: ${{ jobs.reusable.outputs.sha }}
11+
jobs:
12+
reusable:
13+
name: Reusable
14+
runs-on: ubuntu-latest
15+
outputs:
16+
ref: ${{ steps.reusable-workflow.outputs.ref }}
17+
sha: ${{ steps.reusable-workflow.outputs.sha }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
path: reusable-workflow-context
22+
- id: reusable-workflow
23+
uses: ./reusable-workflow-context
24+
with:
25+
path: reusable.yml

.github/workflows/test-local.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test (local)
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
reusable:
9+
uses: ./.github/workflows/reusable.yml
10+
test:
11+
name: Test
12+
needs: [reusable]
13+
runs-on: ubuntu-latest
14+
steps:
15+
- env:
16+
REUSABLE_WORKFLOW_REF: ${{ needs.reusable.outputs.ref }}
17+
REUSABLE_WORKFLOW_SHA: ${{ needs.reusable.outputs.sha }}
18+
run: |
19+
if [[ "$REUSABLE_WORKFLOW_REF" != "$GITHUB_REF" ]]; then
20+
echo "$REUSABLE_WORKFLOW_REF (REUSABLE_WORKFLOW_REF) != $GITHUB_REF"
21+
exit 1
22+
fi
23+
24+
if [[ "$REUSABLE_WORKFLOW_SHA" != "$GITHUB_SHA" ]]; then
25+
echo "$REUSABLE_WORKFLOW_SHA (REUSABLE_WORKFLOW_SHA) != $GITHUB_SHA"
26+
exit 1
27+
fi

.github/workflows/test-ref.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Test (ref)
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
reusable:
9+
uses: ipdxco/reusable-workflow-context/.github/workflows/reusable.yml@main
10+
test:
11+
name: Test
12+
needs: [reusable]
13+
runs-on: ubuntu-latest
14+
steps:
15+
- env:
16+
REUSABLE_WORKFLOW_REF: ${{ needs.reusable.outputs.ref }}
17+
REUSABLE_WORKFLOW_SHA: ${{ needs.reusable.outputs.sha }}
18+
run: |
19+
if [[ "$REUSABLE_WORKFLOW_REF" != "refs/heads/main" ]]; then
20+
echo "$REUSABLE_WORKFLOW_REF (REUSABLE_WORKFLOW_REF) != refs/heads/main"
21+
exit 1
22+
fi

action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Reusable Workflow Context'
2+
description: 'Extracts metadata of the reusable workflow it is used in'
3+
branding:
4+
icon: 'award'
5+
color: 'green'
6+
inputs:
7+
path:
8+
description: 'The path where the reusable workflow is located.'
9+
required: true
10+
outputs:
11+
ref:
12+
description: 'For a reusable workflow executing an action, this is the ref of the reusable workflow being executed.'
13+
value: ${{ fromJSON(steps.context.outputs.json).ref }}
14+
sha:
15+
description: 'For a reusable workflow executing an action, this is the sha of the reusable workflow being executed.'
16+
value: ${{ fromJSON(steps.context.outputs.json).sha }}
17+
runs:
18+
using: 'composite'
19+
steps:
20+
- id: context
21+
env:
22+
WORKFLOW_PATH: ${{ inputs.path }}
23+
GITHUB_TOKEN: ${{ github.token }}
24+
run: gh api repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} | jq -c '.referenced_workflows // [] | map(select(.path | test(env.WORKFLOW_PATH))) | .[0] // {}' | xargs -0 -I {} echo "json={}" | tee -a $GITHUB_OUTPUT
25+
shell: bash

0 commit comments

Comments
 (0)