Skip to content

Commit db37140

Browse files
authored
Refactor environment variable assignments in workflow (#12916)
1 parent 88ffb00 commit db37140

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

.github/workflows/mirror_community_pipeline.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
mirror_community_pipeline:
2525
env:
2626
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_COMMUNITY_MIRROR }}
27-
2827
runs-on: ubuntu-22.04
2928
steps:
3029
# Checkout to correct ref
@@ -39,25 +38,28 @@ jobs:
3938
# If ref is 'refs/heads/main' => set 'main'
4039
# Else it must be a tag => set {tag}
4140
- name: Set checkout_ref and path_in_repo
41+
EVENT_NAME: ${{ github.event_name }}
42+
EVENT_INPUT_REF: ${{ github.event.inputs.ref }}
43+
GITHUB_REF: ${{ github.ref }}
4244
run: |
43-
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
44-
if [ -z "${{ github.event.inputs.ref }}" ]; then
45+
if [ "$EVENT_NAME" == "workflow_dispatch" ]; then
46+
if [ -z "$EVENT_INPUT_REF" ]; then
4547
echo "Error: Missing ref input"
4648
exit 1
47-
elif [ "${{ github.event.inputs.ref }}" == "main" ]; then
49+
elif [ "$EVENT_INPUT_REF" == "main" ]; then
4850
echo "CHECKOUT_REF=refs/heads/main" >> $GITHUB_ENV
4951
echo "PATH_IN_REPO=main" >> $GITHUB_ENV
5052
else
51-
echo "CHECKOUT_REF=refs/tags/${{ github.event.inputs.ref }}" >> $GITHUB_ENV
52-
echo "PATH_IN_REPO=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
53+
echo "CHECKOUT_REF=refs/tags/$EVENT_INPUT_REF" >> $GITHUB_ENV
54+
echo "PATH_IN_REPO=$EVENT_INPUT_REF" >> $GITHUB_ENV
5355
fi
54-
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
55-
echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_ENV
56+
elif [ "$GITHUB_REF" == "refs/heads/main" ]; then
57+
echo "CHECKOUT_REF=$GITHUB_REF" >> $GITHUB_ENV
5658
echo "PATH_IN_REPO=main" >> $GITHUB_ENV
5759
else
5860
# e.g. refs/tags/v0.28.1 -> v0.28.1
59-
echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_ENV
60-
echo "PATH_IN_REPO=$(echo ${{ github.ref }} | sed 's/^refs\/tags\///')" >> $GITHUB_ENV
61+
echo "CHECKOUT_REF=$GITHUB_REF" >> $GITHUB_ENV
62+
echo "PATH_IN_REPO=$(echo $GITHUB_REF | sed 's/^refs\/tags\///')" >> $GITHUB_ENV
6163
fi
6264
- name: Print env vars
6365
run: |
@@ -99,4 +101,4 @@ jobs:
99101
- name: Report failure status
100102
if: ${{ failure() }}
101103
run: |
102-
pip install requests && python utils/notify_community_pipelines_mirror.py --status=failure
104+
pip install requests && python utils/notify_community_pipelines_mirror.py --status=failure

0 commit comments

Comments
 (0)