Skip to content

Commit

Permalink
Merge pull request #128 from guitarrapc/feature/env
Browse files Browse the repository at this point in the history
ci: add env/output for windows
  • Loading branch information
guitarrapc authored Nov 8, 2023
2 parents 147fa89 + c264a64 commit 526a28f
Show file tree
Hide file tree
Showing 16 changed files with 727 additions and 156 deletions.
11 changes: 11 additions & 0 deletions .github/scripts/setenv.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
setlocal
:parse
if "%~1"=="" GOTO endparse
if "%~1"=="--ref" (set _REF=%~2)
shift
GOTO parse
:endparse

echo BRANCH_SCRIPT=%_REF% >> %GITHUB_ENV%
echo branch=%_REF% >> %GITHUB_OUTPUT%
endlocal
6 changes: 6 additions & 0 deletions .github/scripts/setenv.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
param(
[string]$Ref
)

echo "BRANCH_SCRIPT=$Ref" | Tee-Object -Append -FilePath $env:GITHUB_ENV
echo "branch=$Ref" | Tee-Object -Append -FilePath $env:GITHUB_OUTPUT
5 changes: 4 additions & 1 deletion .github/scripts/setenv.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/bash
set -eux

while [ $# -gt 0 ]; do
case $1 in
--ref) GITHUB_REF=$2; shift 2; ;;
*) shift ;;
esac
done

echo GIT_TAG_SCRIPT=${GITHUB_REF##*/} >> "$GITHUB_ENV"
echo BRANCH_SCRIPT=${GITHUB_REF} | tee -a "$GITHUB_ENV"
echo branch=${GITHUB_REF} | tee -a "$GITHUB_OUTPUT"
103 changes: 97 additions & 6 deletions .github/workflows/env_with_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,104 @@ on:
branches: ["main"]
pull_request:
branches: ["main"]

env:
BRANCH_NAME: ${{ startsWith(github.event_name, 'pull_request') && github.head_ref || github.ref_name }}

jobs:
build:
runs-on: ubuntu-latest
bash:
strategy:
matrix:
runs-on: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 3
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- run: echo "GIT_TAG=${GITHUB_REF#refs/heads/}" >> "$GITHUB_ENV"
- run: echo ${{ env.GIT_TAG }}
- run: bash -eux .github/scripts/setenv.sh --ref "${GITHUB_REF#refs/heads/}"
- run: echo ${{ env.GIT_TAG_SCRIPT }}
- name: Add ENV and OUTPUT by shell
id: shell
run: |
echo "BRANCH=${{ env.BRANCH_NAME }}" | tee -a "$GITHUB_ENV"
echo "branch=${{ env.BRANCH_NAME }}" | tee -a "$GITHUB_OUTPUT"
- name: Show ENV and OUTPUT
run: |
echo ${{ env.BRANCH }}
echo ${{ steps.shell.outputs.branch }}
- name: Add ENV and OUTPUT by Script
id: script
run: bash ./.github/scripts/setenv.sh --ref "${{ env.BRANCH_NAME }}"
- name: Show Script ENV and OUTPUT
run: |
echo ${{ env.BRANCH_SCRIPT }}
echo ${{ steps.script.outputs.branch }}
- name: Add PATH
run: echo "$HOME/foo/bar" | tee -a "$GITHUB_PATH"
- name: Show PATH
run: echo "$PATH"

powershell:
strategy:
matrix:
runs-on: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 3
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v4
- name: Add ENV and OUTPUT by shell
id: shell
run: |
echo "BRANCH=${{ env.BRANCH_NAME }}" | Tee-Object -Append -FilePath "${env:GITHUB_ENV}"
echo "branch=${{ env.BRANCH_NAME }}" | Tee-Object -Append -FilePath "${env:GITHUB_OUTPUT}"
- name: Show ENV and OUTPUT
run: |
echo "${{ env.BRANCH }}"
echo "${{ steps.shell.outputs.branch }}"
- name: Add ENV and OUTPUT by Script
id: script
run: ./.github/scripts/setenv.ps1 -Ref "${{ env.BRANCH_NAME }}"
- name: Show Script ENV and OUTPUT
run: |
echo "${{ env.BRANCH_SCRIPT }}"
echo "${{ steps.script.outputs.branch }}"
- name: Add PATH
run: echo "$HOME/foo/bar" | Tee-Object -Append -FilePath "${env:GITHUB_PATH}"
- name: Show PATH
run: echo "${env:PATH}"

cmd:
strategy:
matrix:
runs-on: [windows-latest]
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 3
defaults:
run:
shell: cmd
steps:
- uses: actions/checkout@v4
# cmd must not use quotes!!
- name: Add ENV and OUTPUT by shell
id: shell
run: |
echo BRANCH=${{ env.BRANCH_NAME }} >> %GITHUB_ENV%
echo branch=${{ env.BRANCH_NAME }} >> %GITHUB_OUTPUT%
- name: Show ENV and OUTPUT
run: |
echo ${{ env.BRANCH }}
echo ${{ steps.shell.outputs.branch }}
- name: Add ENV and OUTPUT by Script
id: script
run: .github/scripts/setenv.bat --ref "${{ env.BRANCH_NAME }}"
- name: Show Script ENV and OUTPUT
run: |
echo ${{ env.BRANCH_SCRIPT }}
echo ${{ steps.script.outputs.branch }}
- name: Add PATH
run: echo "%UserProfile%\foo\bar" >> %GITHUB_PATH%
- name: Show PATH
run: echo %PATH%
109 changes: 102 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,17 @@ This syntax can be write in the script, let's see `.github/scripts/setenv.sh`.
# .github/scripts/setenv.sh
#!/bin/bash
set -eux
while [ $# -gt 0 ]; do
case $1 in
--ref) GITHUB_REF=$2; shift 2; ;;
*) shift ;;
esac
done
echo GIT_TAG_SCRIPT=${GITHUB_REF##*/} >> "$GITHUB_ENV"
echo BRANCH_SCRIPT=${GITHUB_REF} | tee -a "$GITHUB_ENV"
echo branch=${GITHUB_REF} | tee -a "$GITHUB_OUTPUT"
```

Expand All @@ -472,16 +475,108 @@ on:
branches: ["main"]
pull_request:
branches: ["main"]
env:
BRANCH_NAME: ${{ startsWith(github.event_name, 'pull_request') && github.head_ref || github.ref_name }}
jobs:
build:
runs-on: ubuntu-latest
bash:
strategy:
matrix:
runs-on: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 3
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Add ENV and OUTPUT by shell
id: shell
run: |
echo "BRANCH=${{ env.BRANCH_NAME }}" | tee -a "$GITHUB_ENV"
echo "branch=${{ env.BRANCH_NAME }}" | tee -a "$GITHUB_OUTPUT"
- name: Show ENV and OUTPUT
run: |
echo ${{ env.BRANCH }}
echo ${{ steps.shell.outputs.branch }}
- name: Add ENV and OUTPUT by Script
id: script
run: bash ./.github/scripts/setenv.sh --ref "${{ env.BRANCH_NAME }}"
- name: Show Script ENV and OUTPUT
run: |
echo ${{ env.BRANCH_SCRIPT }}
echo ${{ steps.script.outputs.branch }}
- name: Add PATH
run: echo "$HOME/foo/bar" | tee -a "$GITHUB_PATH"
- name: Show PATH
run: echo "$PATH"
powershell:
strategy:
matrix:
runs-on: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 3
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v4
- name: Add ENV and OUTPUT by shell
id: shell
run: |
echo "BRANCH=${{ env.BRANCH_NAME }}" | Tee-Object -Append -FilePath "${env:GITHUB_ENV}"
echo "branch=${{ env.BRANCH_NAME }}" | Tee-Object -Append -FilePath "${env:GITHUB_OUTPUT}"
- name: Show ENV and OUTPUT
run: |
echo "${{ env.BRANCH }}"
echo "${{ steps.shell.outputs.branch }}"
- name: Add ENV and OUTPUT by Script
id: script
run: ./.github/scripts/setenv.ps1 -Ref "${{ env.BRANCH_NAME }}"
- name: Show Script ENV and OUTPUT
run: |
echo "${{ env.BRANCH_SCRIPT }}"
echo "${{ steps.script.outputs.branch }}"
- name: Add PATH
run: echo "$HOME/foo/bar" | Tee-Object -Append -FilePath "${env:GITHUB_PATH}"
- name: Show PATH
run: echo "${env:PATH}"
cmd:
strategy:
matrix:
runs-on: [windows-latest]
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 3
defaults:
run:
shell: cmd
steps:
- uses: actions/checkout@v4
- run: echo "GIT_TAG=${GITHUB_REF#refs/heads/}" >> "$GITHUB_ENV"
- run: echo ${{ env.GIT_TAG }}
- run: bash -eux .github/scripts/setenv.sh --ref "${GITHUB_REF#refs/heads/}"
- run: echo ${{ env.GIT_TAG_SCRIPT }}
# cmd must not use quotes!!
- name: Add ENV and OUTPUT by shell
id: shell
run: |
echo BRANCH=${{ env.BRANCH_NAME }} >> %GITHUB_ENV%
echo branch=${{ env.BRANCH_NAME }} >> %GITHUB_OUTPUT%
- name: Show ENV and OUTPUT
run: |
echo ${{ env.BRANCH }}
echo ${{ steps.shell.outputs.branch }}
- name: Add ENV and OUTPUT by Script
id: script
run: .github/scripts/setenv.bat --ref "${{ env.BRANCH_NAME }}"
- name: Show Script ENV and OUTPUT
run: |
echo ${{ env.BRANCH_SCRIPT }}
echo ${{ steps.script.outputs.branch }}
- name: Add PATH
run: echo "%UserProfile%\foo\bar" >> %GITHUB_PATH%
- name: Show PATH
run: echo %PATH%
```

## If and context reference
Expand Down
46 changes: 46 additions & 0 deletions contexts/export/pull_request_opened.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ declare -x GITHUB_ACTOR="guitarrapc"
declare -x GITHUB_ACTOR_ID="3856350"
declare -x GITHUB_API_URL="https://api.github.com"
declare -x GITHUB_BASE_REF="main"
<<<<<<< HEAD
declare -x GITHUB_ENV="/home/runner/work/_temp/_runner_file_commands/set_env_dcdf0284-d4a4-4558-a0f0-c05545abaf2e"
declare -x GITHUB_EVENT_NAME="pull_request"
declare -x GITHUB_EVENT_PATH="/home/runner/work/_temp/_github_workflow/event.json"
declare -x GITHUB_GRAPHQL_URL="https://api.github.com/graphql"
declare -x GITHUB_HEAD_REF="feature/env"
declare -x GITHUB_JOB="dump-context"
declare -x GITHUB_OUTPUT="/home/runner/work/_temp/_runner_file_commands/set_output_dcdf0284-d4a4-4558-a0f0-c05545abaf2e"
declare -x GITHUB_PATH="/home/runner/work/_temp/_runner_file_commands/add_path_dcdf0284-d4a4-4558-a0f0-c05545abaf2e"
declare -x GITHUB_REF="refs/pull/128/merge"
declare -x GITHUB_REF_NAME="128/merge"
=======
declare -x GITHUB_ENV="/home/runner/work/_temp/_runner_file_commands/set_env_8a4b4333-134c-4097-8a44-66231d56e65d"
declare -x GITHUB_EVENT_NAME="pull_request"
declare -x GITHUB_EVENT_PATH="/home/runner/work/_temp/_github_workflow/event.json"
Expand All @@ -41,6 +53,7 @@ declare -x GITHUB_OUTPUT="/home/runner/work/_temp/_runner_file_commands/set_outp
declare -x GITHUB_PATH="/home/runner/work/_temp/_runner_file_commands/add_path_8a4b4333-134c-4097-8a44-66231d56e65d"
declare -x GITHUB_REF="refs/pull/131/merge"
declare -x GITHUB_REF_NAME="131/merge"
>>>>>>> main
declare -x GITHUB_REF_PROTECTED="false"
declare -x GITHUB_REF_TYPE="branch"
declare -x GITHUB_REPOSITORY="guitarrapc/githubactions-lab"
Expand All @@ -49,6 +62,18 @@ declare -x GITHUB_REPOSITORY_OWNER="guitarrapc"
declare -x GITHUB_REPOSITORY_OWNER_ID="3856350"
declare -x GITHUB_RETENTION_DAYS="90"
declare -x GITHUB_RUN_ATTEMPT="1"
<<<<<<< HEAD
declare -x GITHUB_RUN_ID="6793559829"
declare -x GITHUB_RUN_NUMBER="390"
declare -x GITHUB_SERVER_URL="https://github.com"
declare -x GITHUB_SHA="657af584390d0d9846ae0ddb1f0daf7a724dbb7d"
declare -x GITHUB_STATE="/home/runner/work/_temp/_runner_file_commands/save_state_dcdf0284-d4a4-4558-a0f0-c05545abaf2e"
declare -x GITHUB_STEP_SUMMARY="/home/runner/work/_temp/_runner_file_commands/step_summary_dcdf0284-d4a4-4558-a0f0-c05545abaf2e"
declare -x GITHUB_TRIGGERING_ACTOR="guitarrapc"
declare -x GITHUB_WORKFLOW="auto dump context"
declare -x GITHUB_WORKFLOW_REF="guitarrapc/githubactions-lab/.github/workflows/auto_dump_context.yaml@refs/pull/128/merge"
declare -x GITHUB_WORKFLOW_SHA="657af584390d0d9846ae0ddb1f0daf7a724dbb7d"
=======
declare -x GITHUB_RUN_ID="6794643065"
declare -x GITHUB_RUN_NUMBER="407"
declare -x GITHUB_SERVER_URL="https://github.com"
Expand All @@ -59,6 +84,7 @@ declare -x GITHUB_TRIGGERING_ACTOR="guitarrapc"
declare -x GITHUB_WORKFLOW="auto dump context"
declare -x GITHUB_WORKFLOW_REF="guitarrapc/githubactions-lab/.github/workflows/auto_dump_context.yaml@refs/pull/131/merge"
declare -x GITHUB_WORKFLOW_SHA="1be9b9f200e0f2b0c8fa99a5d3248a035edf6970"
>>>>>>> main
declare -x GITHUB_WORKSPACE="/home/runner/work/githubactions-lab/githubactions-lab"
declare -x GOROOT_1_19_X64="/opt/hostedtoolcache/go/1.19.13/x64"
declare -x GOROOT_1_20_X64="/opt/hostedtoolcache/go/1.20.10/x64"
Expand All @@ -67,15 +93,23 @@ declare -x GRADLE_HOME="/usr/share/gradle-8.4"
declare -x HOME="/home/runner"
declare -x HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS="3650"
declare -x HOMEBREW_NO_AUTO_UPDATE="1"
<<<<<<< HEAD
declare -x INVOCATION_ID="709dfeceeae74cdeb32f74d16ce5c494"
=======
declare -x INVOCATION_ID="b02e80e6600249cfb74f01c93a8d15a1"
>>>>>>> main
declare -x ImageOS="ubuntu22"
declare -x ImageVersion="20231030.2.0"
declare -x JAVA_HOME="/usr/lib/jvm/temurin-11-jdk-amd64"
declare -x JAVA_HOME_11_X64="/usr/lib/jvm/temurin-11-jdk-amd64"
declare -x JAVA_HOME_17_X64="/usr/lib/jvm/temurin-17-jdk-amd64"
declare -x JAVA_HOME_21_X64="/usr/lib/jvm/temurin-21-jdk-amd64"
declare -x JAVA_HOME_8_X64="/usr/lib/jvm/temurin-8-jdk-amd64"
<<<<<<< HEAD
declare -x JOURNAL_STREAM="8:18949"
=======
declare -x JOURNAL_STREAM="8:20500"
>>>>>>> main
declare -x LANG="C.UTF-8"
declare -x LEIN_HOME="/usr/local/lib/lein"
declare -x LEIN_JAR="/usr/local/lib/lein/self-installs/leiningen-2.10.0-standalone.jar"
Expand All @@ -90,12 +124,20 @@ declare -x POWERSHELL_DISTRIBUTION_CHANNEL="GitHub-Actions-ubuntu22"
declare -x PWD="/home/runner/work/githubactions-lab/githubactions-lab"
declare -x RUNNER_ARCH="X64"
declare -x RUNNER_ENVIRONMENT="github-hosted"
<<<<<<< HEAD
declare -x RUNNER_NAME="GitHub Actions 23"
=======
declare -x RUNNER_NAME="GitHub Actions 33"
>>>>>>> main
declare -x RUNNER_OS="Linux"
declare -x RUNNER_PERFLOG="/home/runner/perflog"
declare -x RUNNER_TEMP="/home/runner/work/_temp"
declare -x RUNNER_TOOL_CACHE="/opt/hostedtoolcache"
<<<<<<< HEAD
declare -x RUNNER_TRACKING_ID="github_1f2e650c-1a6b-4356-bf46-c57da7640903"
=======
declare -x RUNNER_TRACKING_ID="github_eaab5e0a-a854-4f33-9168-7a3fbae75d1a"
>>>>>>> main
declare -x RUNNER_USER="runner"
declare -x RUNNER_WORKSPACE="/home/runner/work/githubactions-lab"
declare -x SELENIUM_JAR_PATH="/usr/share/java/selenium-server.jar"
Expand All @@ -111,7 +153,11 @@ declare -x STATS_UE="true"
declare -x STATS_V3PS="true"
declare -x STATS_VMD="true"
declare -x SWIFT_PATH="/usr/share/swift/usr/bin"
<<<<<<< HEAD
declare -x SYSTEMD_EXEC_PID="591"
=======
declare -x SYSTEMD_EXEC_PID="611"
>>>>>>> main
declare -x USER="runner"
declare -x VCPKG_INSTALLATION_ROOT="/usr/local/share/vcpkg"
declare -x XDG_CONFIG_HOME="/home/runner/.config"
Expand Down
Loading

0 comments on commit 526a28f

Please sign in to comment.