Skip to content

Commit a3b744e

Browse files
Refactor Github Action per b/485167538
1 parent a847a8d commit a3b744e

File tree

11 files changed

+57
-25
lines changed

11 files changed

+57
-25
lines changed

.github/actions/bash/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ runs:
2424

2525
- name: Run
2626
shell: bash
27-
run: ${{ inputs.command }}
27+
run: ${INPUTS_COMMAND}
28+
env:
29+
INPUTS_COMMAND: ${{ inputs.command }}

.github/actions/bazel-docker/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ runs:
4747

4848
- name: Hook up repository Cache
4949
shell: bash
50-
run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --repository_cache='/workspace/${{ env.REPOSITORY_CACHE_PATH }}'" >> $GITHUB_ENV
50+
run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --repository_cache='/workspace/${REPOSITORY_CACHE_PATH}'" >> $GITHUB_ENV
5151

5252
- name: Validate inputs
5353
if: ${{ (inputs.bash && inputs.bazel) || (!inputs.bash && !inputs.bazel) }}

.github/actions/bazel/action.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ runs:
7878

7979
- name: Hook up repository Cache
8080
shell: bash
81-
run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --repository_cache=$(pwd)/${{ env.REPOSITORY_CACHE_PATH }}" >> $GITHUB_ENV
81+
run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --repository_cache=$(pwd)/${REPOSITORY_CACHE_PATH}" >> $GITHUB_ENV
8282

8383
- name: Validate inputs
8484
if: ${{ (inputs.bash && inputs.bazel) || (!inputs.bash && !inputs.bazel) }}
@@ -87,23 +87,30 @@ runs:
8787

8888
- name: Pin Bazel version
8989
shell: bash
90-
run: echo "USE_BAZEL_VERSION=${{ inputs.version }}" >> $GITHUB_ENV
90+
run: echo "USE_BAZEL_VERSION=${INPUTS_VERSION}" >> $GITHUB_ENV
91+
env:
92+
INPUTS_VERSION: ${{ inputs.version }}
9193

9294
- name: Output Bazel version
9395
shell: bash
9496
run: bazelisk version
9597

9698
- name: Run Bash
9799
if: ${{ inputs.bash }}
98-
run: ${{ inputs.bash }}
100+
run: ${INPUTS_BASH}
99101
shell: bash
102+
env:
103+
INPUTS_BASH: ${{ inputs.bash }}
100104

101105
- name: Run Bazel
102106
if: ${{ !inputs.bash }}
103107
run: >-
104-
bazelisk ${{ steps.bazel.outputs.bazel-startup-flags }}
105-
${{ inputs.bazel }} $BAZEL_FLAGS
108+
bazelisk ${STEPS_BAZEL_OUTPUTS_BAZEL_STARTUP_FLAGS}
109+
${INPUTS_BAZEL} $BAZEL_FLAGS
106110
shell: bash
111+
env:
112+
STEPS_BAZEL_OUTPUTS_BAZEL_STARTUP_FLAGS: ${{ steps.bazel.outputs.bazel-startup-flags }}
113+
INPUTS_BAZEL: ${{ inputs.bazel }}
107114

108115
- name: Save Bazel repository cache
109116
# Only allow repository cache updates during post-submits.

.github/actions/cross-compile-protoc/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ runs:
2828
2929
- name: Set protoc environment variable
3030
shell: bash
31-
run: echo "PROTOC=protoc-${{ inputs.architecture }}" >> $GITHUB_ENV
31+
run: echo "PROTOC=protoc-${INPUTS_ARCHITECTURE}" >> $GITHUB_ENV
32+
env:
33+
INPUTS_ARCHITECTURE: ${{ inputs.architecture }}
3234

3335
- name: Extract binary
3436
id: output

.github/actions/docker/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ runs:
4040
- name: Generate docker flags
4141
if: inputs.platform
4242
shell: bash
43-
run: echo "DOCKER_RUN_FLAGS=--platform ${{inputs.platform}}" >> $GITHUB_ENV
43+
run: echo "DOCKER_RUN_FLAGS=--platform ${INPUTS_PLATFORM}" >> $GITHUB_ENV
44+
env:
45+
INPUTS_PLATFORM: ${{inputs.platform}}
4446

4547
- name: Run Docker
4648
uses: ./.github/actions/internal/docker-run

.github/actions/internal/bazel-setup/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ runs:
5151
shell: bash
5252
run: >-
5353
echo "BAZEL_FLAGS=$BAZEL_FLAGS
54-
--google_credentials=${{ inputs.credentials-file }}
55-
--remote_cache=https://storage.googleapis.com/protobuf-bazel-cache/protobuf/gha/${{ inputs.bazel-cache }}" >> $GITHUB_ENV
54+
--google_credentials=${INPUTS_CREDENTIALS_FILE}
55+
--remote_cache=https://storage.googleapis.com/protobuf-bazel-cache/protobuf/gha/${INPUTS_BAZEL_CACHE}" >> $GITHUB_ENV
56+
env:
57+
INPUTS_CREDENTIALS_FILE: ${{ inputs.credentials-file }}
58+
INPUTS_BAZEL_CACHE: ${{ inputs.bazel-cache }}
5659

5760
- name: Configure Bazel cache writing
5861
# External runs should never write to our caches.

.github/actions/internal/docker-run/action.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,32 @@ runs:
4141
shell: bash
4242
if: ${{ inputs.docker-cache && steps.check-docker-cache.outputs.cache-hit != 'true' }}
4343
run: >
44-
time docker pull -q ${{ inputs.image }} &&
45-
mkdir -p ci/docker/$(dirname ${{ inputs.image }}) &&
46-
time docker image save ${{ inputs.image }} --output ./ci/docker/${{ inputs.image }}.tar
44+
time docker pull -q ${INPUTS_IMAGE} &&
45+
mkdir -p ci/docker/$(dirname ${INPUTS_IMAGE}) &&
46+
time docker image save ${INPUTS_IMAGE} --output ./ci/docker/${INPUTS_IMAGE}.tar
47+
env:
48+
INPUTS_IMAGE: ${{ inputs.image }}
4749

4850
- name: Use the cached image on cache hit
4951
shell: bash
5052
if: ${{ inputs.docker-cache && steps.check-docker-cache.outputs.cache-hit == 'true' }}
51-
run: time docker image load --input ./ci/docker/${{ inputs.image }}.tar
53+
run: time docker image load --input ./ci/docker/${INPUTS_IMAGE}.tar
54+
env:
55+
INPUTS_IMAGE: ${{ inputs.image }}
5256

5357
- name: Pull fresh docker image
5458
shell: bash
5559
if: ${{ !inputs.docker-cache }}
56-
run: time docker pull -q ${{ inputs.image }}
60+
run: time docker pull -q ${INPUTS_IMAGE}
61+
env:
62+
INPUTS_IMAGE: ${{ inputs.image }}
5763

5864
- name: Run docker
5965
shell: bash
6066
run: >
61-
time docker run ${{ inputs.run-flags}} -v${{ github.workspace }}:/workspace
62-
${{ inputs.image }} ${{ inputs.command }}
67+
time docker run ${INPUTS_RUN_FLAGS} -v${{ github.workspace }}:/workspace
68+
${INPUTS_IMAGE} ${INPUTS_COMMAND}
69+
env:
70+
INPUTS_RUN_FLAGS: ${{ inputs.run-flags}}
71+
INPUTS_IMAGE: ${{ inputs.image }}
72+
INPUTS_COMMAND: ${{ inputs.command }}

.github/actions/internal/gcloud-auth/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ runs:
2727

2828
- name: Store credentials path
2929
shell: bash
30-
run: echo "CREDENTIALS_FILE=${{ steps.auth.outputs.credentials_file_path }}" >> $GITHUB_ENV
30+
run: echo "CREDENTIALS_FILE=${STEPS_AUTH_OUTPUTS_CREDENTIALS_FILE_PATH}" >> $GITHUB_ENV
31+
env:
32+
STEPS_AUTH_OUTPUTS_CREDENTIALS_FILE_PATH: ${{ steps.auth.outputs.credentials_file_path }}
3133

3234
- name: Fix credentials path (Windows)
3335
if: ${{ runner.os == 'Windows' }}
@@ -39,4 +41,4 @@ runs:
3941
- name: Output credentials file
4042
id: output
4143
shell: bash
42-
run: echo "credentials-file=${{ env.CREDENTIALS_FILE }}" >> $GITHUB_OUTPUT
44+
run: echo "credentials-file=${CREDENTIALS_FILE}" >> $GITHUB_OUTPUT

.github/actions/internal/repository-cache-restore/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ runs:
2424
run: |
2525
REPOSITORY_CACHE_BASE=repository-cache-${{ github.base_ref || github.ref_name }}-${{ runner.os }}
2626
echo "REPOSITORY_CACHE_BASE=$REPOSITORY_CACHE_BASE" >> $GITHUB_ENV
27-
echo "REPOSITORY_CACHE_NAME=$REPOSITORY_CACHE_BASE-${{ inputs.bazel-cache}}-${{ github.sha }}" >> $GITHUB_ENV
27+
echo "REPOSITORY_CACHE_NAME=$REPOSITORY_CACHE_BASE-${INPUTS_BAZEL_CACHE}-${{ github.sha }}" >> $GITHUB_ENV
2828
echo "REPOSITORY_CACHE_PATH=.repository-cache" >> $GITHUB_ENV
29+
env:
30+
INPUTS_BAZEL_CACHE: ${{ inputs.bazel-cache}}
2931

3032
- name: Restore Bazel repository cache
3133
id: restore-cache

.github/workflows/forked_pr_workflow_check.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ jobs:
2424
steps:
2525
- run: >
2626
${{ github.event.pull_request.head.repo.full_name == 'protocolbuffers/protobuf' }} ||
27-
(echo "This pull request is from an unsafe fork (${{ github.event.pull_request.head.repo.full_name }}) and isn't allowed to modify workflow files!" && exit 1)
27+
(echo "This pull request is from an unsafe fork (${GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME}) and isn't allowed to modify workflow files!" && exit 1)
28+
env:
29+
GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}

0 commit comments

Comments
 (0)