forked from conda-forge/qsimcirq-feedstock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_conda_build_artifacts.sh
executable file
·113 lines (92 loc) · 4.12 KB
/
create_conda_build_artifacts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# INPUTS (environment variables that need to be set before calling this script):
#
# CI (azure/github_actions/UNSET)
# CI_RUN_ID (unique identifier for the CI job run)
# FEEDSTOCK_NAME
# CONFIG (build matrix configuration string)
# SHORT_CONFIG (uniquely-shortened configuration string)
# CONDA_BLD_DIR (path to the conda-bld directory)
# ARTIFACT_STAGING_DIR (use working directory if unset)
# BLD_ARTIFACT_PREFIX (prefix for the conda build artifact name, skip if unset)
# ENV_ARTIFACT_PREFIX (prefix for the conda build environments artifact name, skip if unset)
# OUTPUTS
#
# BLD_ARTIFACT_NAME
# BLD_ARTIFACT_PATH
# ENV_ARTIFACT_NAME
# ENV_ARTIFACT_PATH
source .scripts/logging_utils.sh
# DON'T do set -x, because it results in double echo-ing pipeline commands
# and that might end up inserting extraneous quotation marks in output variables
set -e
# Check that the conda-build directory exists
if [ ! -d "$CONDA_BLD_DIR" ]; then
echo "conda-build directory does not exist"
exit 1
fi
# Set staging dir to the working dir, in Windows style if applicable
if [[ -z "${ARTIFACT_STAGING_DIR}" ]]; then
if pwd -W; then
ARTIFACT_STAGING_DIR=$(pwd -W)
else
ARTIFACT_STAGING_DIR=$PWD
fi
fi
echo "ARTIFACT_STAGING_DIR: $ARTIFACT_STAGING_DIR"
FEEDSTOCK_ROOT=$(cd "$(dirname "$0")/.."; pwd;)
if [ -z ${FEEDSTOCK_NAME} ]; then
export FEEDSTOCK_NAME=$(basename ${FEEDSTOCK_ROOT})
fi
# Set a unique ID for the artifact(s), specialized for this particular job run
ARTIFACT_UNIQUE_ID="${CI_RUN_ID}_${CONFIG}"
if [[ ${#ARTIFACT_UNIQUE_ID} -gt 80 ]]; then
ARTIFACT_UNIQUE_ID="${CI_RUN_ID}_${SHORT_CONFIG}"
fi
echo "ARTIFACT_UNIQUE_ID: $ARTIFACT_UNIQUE_ID"
# Set a descriptive ID for the archive(s), specialized for this particular job run
ARCHIVE_UNIQUE_ID="${CI_RUN_ID}_${CONFIG}"
# Make the build artifact zip
if [[ ! -z "$BLD_ARTIFACT_PREFIX" ]]; then
export BLD_ARTIFACT_NAME="${BLD_ARTIFACT_PREFIX}_${ARTIFACT_UNIQUE_ID}"
export BLD_ARTIFACT_PATH="${ARTIFACT_STAGING_DIR}/${FEEDSTOCK_NAME}_${BLD_ARTIFACT_PREFIX}_${ARCHIVE_UNIQUE_ID}.zip"
( startgroup "Archive conda build directory" ) 2> /dev/null
# Try 7z and fall back to zip if it fails (for cross-platform use)
if ! 7z a "$BLD_ARTIFACT_PATH" "$CONDA_BLD_DIR" '-xr!.git/' '-xr!_*_env*/' '-xr!*_cache/' -bb; then
pushd "$CONDA_BLD_DIR"
zip -r -y -T "$BLD_ARTIFACT_PATH" . -x '*.git/*' '*_*_env*/*' '*_cache/*'
popd
fi
( endgroup "Archive conda build directory" ) 2> /dev/null
echo "BLD_ARTIFACT_NAME: $BLD_ARTIFACT_NAME"
echo "BLD_ARTIFACT_PATH: $BLD_ARTIFACT_PATH"
if [[ "$CI" == "azure" ]]; then
echo "##vso[task.setVariable variable=BLD_ARTIFACT_NAME]$BLD_ARTIFACT_NAME"
echo "##vso[task.setVariable variable=BLD_ARTIFACT_PATH]$BLD_ARTIFACT_PATH"
elif [[ "$CI" == "github_actions" ]]; then
echo "BLD_ARTIFACT_NAME=$BLD_ARTIFACT_NAME" >> $GITHUB_OUTPUT
echo "BLD_ARTIFACT_PATH=$BLD_ARTIFACT_PATH" >> $GITHUB_OUTPUT
fi
fi
# Make the environments artifact zip
if [[ ! -z "$ENV_ARTIFACT_PREFIX" ]]; then
export ENV_ARTIFACT_NAME="${ENV_ARTIFACT_PREFIX}_${ARTIFACT_UNIQUE_ID}"
export ENV_ARTIFACT_PATH="${ARTIFACT_STAGING_DIR}/${FEEDSTOCK_NAME}_${ENV_ARTIFACT_PREFIX}_${ARCHIVE_UNIQUE_ID}.zip"
( startgroup "Archive conda build environments" ) 2> /dev/null
# Try 7z and fall back to zip if it fails (for cross-platform use)
if ! 7z a "$ENV_ARTIFACT_PATH" -r "$CONDA_BLD_DIR"/'_*_env*/' -bb; then
pushd "$CONDA_BLD_DIR"
zip -r -y -T "$ENV_ARTIFACT_PATH" . -i '*_*_env*/*'
popd
fi
( endgroup "Archive conda build environments" ) 2> /dev/null
echo "ENV_ARTIFACT_NAME: $ENV_ARTIFACT_NAME"
echo "ENV_ARTIFACT_PATH: $ENV_ARTIFACT_PATH"
if [[ "$CI" == "azure" ]]; then
echo "##vso[task.setVariable variable=ENV_ARTIFACT_NAME]$ENV_ARTIFACT_NAME"
echo "##vso[task.setVariable variable=ENV_ARTIFACT_PATH]$ENV_ARTIFACT_PATH"
elif [[ "$CI" == "github_actions" ]]; then
echo "ENV_ARTIFACT_NAME=$ENV_ARTIFACT_NAME" >> $GITHUB_OUTPUT
echo "ENV_ARTIFACT_PATH=$ENV_ARTIFACT_PATH" >> $GITHUB_OUTPUT
fi
fi