mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 17:32:56 +00:00
## Problem In several workflows, we have repeating code which is separated into two steps: ```bash mkdir -p $(pwd)/.docker-custom echo DOCKER_CONFIG=/tmp/.docker-custom >> $GITHUB_ENV ... rm -rf $(pwd)/.docker-custom ``` Such copy-paste is prone to errors; for example, in one case, instead of `$(pwd)/.docker-custom`, we use `/tmp/.docker-custom`, which is shared between workflows. ## Summary of changes - Create a new action `actions/set-docker-config-dir`, which sets `DOCKER_CONFIG` and deletes it in a Post action part
37 lines
1.7 KiB
YAML
37 lines
1.7 KiB
YAML
name: "Set custom docker config directory"
|
|
description: "Create a directory for docker config and set DOCKER_CONFIG"
|
|
|
|
# Use custom DOCKER_CONFIG directory to avoid conflicts with default settings
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Show warning on GitHub-hosted runners
|
|
if: runner.environment == 'github-hosted'
|
|
shell: bash -euo pipefail {0}
|
|
run: |
|
|
# Using the following environment variables to find a path to the workflow file
|
|
# ${GITHUB_WORKFLOW_REF} - octocat/hello-world/.github/workflows/my-workflow.yml@refs/heads/my_branch
|
|
# ${GITHUB_REPOSITORY} - octocat/hello-world
|
|
# ${GITHUB_REF} - refs/heads/my_branch
|
|
# From https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/variables
|
|
|
|
filename_with_ref=${GITHUB_WORKFLOW_REF#"$GITHUB_REPOSITORY/"}
|
|
filename=${filename_with_ref%"@$GITHUB_REF"}
|
|
|
|
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-warning-message
|
|
title='Unnecessary usage of `.github/actions/set-docker-config-dir`'
|
|
message='No need to use `.github/actions/set-docker-config-dir` action on GitHub-hosted runners'
|
|
echo "::warning file=${filename},title=${title}::${message}"
|
|
|
|
- uses: pyTooling/Actions/with-post-step@74afc5a42a17a046c90c68cb5cfa627e5c6c5b6b # v1.0.7
|
|
env:
|
|
DOCKER_CONFIG: .docker-custom-${{ github.run_id }}-${{ github.run_attempt }}
|
|
with:
|
|
main: |
|
|
mkdir -p "${DOCKER_CONFIG}"
|
|
echo DOCKER_CONFIG=${DOCKER_CONFIG} | tee -a $GITHUB_ENV
|
|
post: |
|
|
if [ -d "${DOCKER_CONFIG}" ]; then
|
|
rm -r "${DOCKER_CONFIG}"
|
|
fi
|