Skip to content

Commit

Permalink
Added pass-action-output-to-job-environment workflow (#10)
Browse files Browse the repository at this point in the history
* Added pass-action-output-to-job-environment workflow

* Added environment to workflow

* Changed step id from step in action to step in workflow

* Added stept to echo output

* Simplified step

* Echo env var directly

* Echoed inside action output

* Use ::set-output in action

* Added echo step inside action

* Added expression syntax

* Use matrix strategy

* Added environment input to action

* Set environment url from step outputs
  • Loading branch information
NickGraham101 authored Apr 13, 2022
1 parent 2ed9413 commit c2e7dd8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/actions/action-with-output-from-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: action-with-output-from-env
description: Action With Output From Env

inputs:
environment:
required: true

outputs:
env-url:
description: "URL from action env var"
value: ${{ env.URL }}
output-url:
description: "URL from step output"
value: ${{ steps.step-inside-action.outputs.step-url }}

runs:
using: composite
steps:
- name: step inside action
id: step-inside-action
shell: bash
run: |
echo "URL is https://example.com/${{ inputs.environment }}"
echo "URL=https://example.com/${{ inputs.environment }}" >> $GITHUB_ENV
echo "::set-output name=step-url::https://example.com/${{ inputs.environment }}"
- name: echo step inside action output
id: echo-step-inside-action-output
shell: bash
run: echo ${{ steps.step-inside-action.outputs.step-url }}
33 changes: 33 additions & 0 deletions .github/workflows/pass-action-output-to-job-environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PassActionOutputToJobEnvironment

on:
pull_request:
workflow_dispatch:

jobs:
test:
name: Pass Action Output To Job Environment
environment:
name: ${{ matrix.environment }}
url: ${{ steps.call-action-step.outputs.output-url }}
runs-on: ubuntu-latest
strategy:
matrix:
environment: [Test,Staging]
steps:
- name: Checkout
uses: actions/checkout@v2.4.0

- name: Step Outputs In Action
id: call-action-step
uses: ./.github/actions/action-with-output-from-env/
with:
environment: ${{ matrix.environment }}

- name: Echo Output
run: |
echo ${{ steps.step-inside-action.outputs.env-url }}
echo ${{ steps.call-action-step.outputs.env-url }}
echo ${{ env.URL }}
echo ${{ steps.step-inside-action.outputs.output-url }}
echo ${{ steps.call-action-step.outputs.output-url }}

0 comments on commit c2e7dd8

Please sign in to comment.