Syncing versions manager #11450
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Syncing versions manager | |
on: | |
workflow_dispatch: | |
push: | |
schedule: | |
- cron: "* */6 * * *" | |
env: | |
VERSIONS_JSON: ${{ vars.VERSIONS }} | |
WARNING_HEADER: > | |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\n | |
# This file is auto generated by the github sync version manager workflow #\n | |
# Do not modify it directly, use the github configuration variables instead. #\n | |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\n | |
TORCH_BASE_URL: https://download.pytorch.org/libtorch/cpu/ | |
jobs: | |
sync-variables: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Parse JSON variable | |
run: | | |
cat <<EOF > /tmp/versions.json | |
${{ env.VERSIONS_JSON }} | |
EOF | |
cat /tmp/versions.json | jq 2>&1 | |
EXIT_STATUS=$? | |
if ! (exit $EXIT_STATUS); then | |
exit $EXIT_STATUS | |
fi | |
echo "VERSIONS_OBJECT=$(cat /tmp/versions.json | jq -c '.')" >> $GITHUB_ENV | |
echo "Parsed JSON object: $VERSIONS_OBJECT" | |
- name: Verify JSON parsing | |
if: ${{ failure() }} | |
run: | | |
echo | |
echo "JSON Error: github VERSIONS variable is bad formatted! ❌ 😔" | |
echo "${{ vars.VERSIONS }}" | |
- name: Env file creation | |
run: | | |
echo -e " ${{ env.WARNING_HEADER }}" > /tmp/env.tmp | |
for key in $(echo "${VERSIONS_OBJECT}" | jq -r 'keys[]'); do | |
value=$(echo "${VERSIONS_OBJECT}" | jq -r --arg k "$key" '.[$k]') | |
echo "${key^^}=\"${value}\"" | |
echo "${key^^}=\"${value}\"" >> /tmp/env.tmp | |
if [ "${key^^}" == "TORCH_VERSION" ]; then | |
# Generate torch links | |
TORCH_URL="${TORCH_BASE_URL}libtorch-shared-with-deps-\${${key^^}}%2Bcpu.zip" | |
TORCH_CXX11_URL="${TORCH_BASE_URL}libtorch-cxx11-abi-shared-with-deps-\${${key^^}}%2Bcpu.zip" | |
# Add them to /tmp/env.tmp | |
printf '%s\n%s\n' "TORCH_URL=\"${TORCH_URL}\"" "TORCH_CXX11_URL=\"${TORCH_CXX11_URL}\"" >> /tmp/env.tmp | |
fi | |
done | |
- name: Update .env.vars | |
run: | | |
if [ -f ".env.vars" ]; then | |
tmpfile=$(cat /tmp/env.tmp) | |
varfile=$(cat .env.vars) | |
if [ "$tmpfile" != "$varfile" ]; then | |
mv /tmp/env.tmp .env.vars | |
else | |
echo "Already up to date!" | |
exit 0 | |
fi | |
else | |
mv /tmp/env.tmp .env.vars | |
fi | |
- name: version.py file creation | |
run: | | |
echo -e " ${{ env.WARNING_HEADER }}" > /tmp/version.py | |
# Define list of objects __all__ | |
echo "__all__= [" >> /tmp/version.py | |
for key in $(echo "${VERSIONS_OBJECT}" | jq -r 'keys[]'); do | |
value=$(echo "${VERSIONS_OBJECT}" | jq -r --arg k "$key" '.[$k]') | |
echo " \"__${key,,}__\"," >> /tmp/version.py | |
if [ "${key^^}" == "TORCH_VERSION" ]; then | |
echo " \"__torch_url__\"," >> /tmp/version.py | |
echo " \"__torch_cxx11_url__\"," >> /tmp/version.py | |
fi | |
done | |
echo "]" >> /tmp/version.py | |
# Init variables | |
for key in $(echo "${VERSIONS_OBJECT}" | jq -r 'keys[]'); do | |
value=$(echo "${VERSIONS_OBJECT}" | jq -r --arg k "$key" '.[$k]') | |
echo "__${key,,}__ = \"${value}\"" >> /tmp/version.py | |
if [ "${key^^}" == "TORCH_VERSION" ]; then | |
# Generate torch links | |
TORCH_URL="${TORCH_BASE_URL}libtorch-shared-with-deps-\"+__${key,,}__+\"%2Bcpu.zip" | |
TORCH_CXX11_URL="${TORCH_BASE_URL}libtorch-cxx11-abi-shared-with-deps-\"+__${key,,}__+\"%2Bcpu.zip" | |
# Add them to /tmp/version.py | |
printf '%s\n%s\n' "__torch_url__ = \"${TORCH_URL}\"" "__torch_cxx11_url__ = \"${TORCH_CXX11_URL}\"" >> /tmp/version.py | |
fi | |
done | |
pip install black | |
black /tmp/version.py | |
- name: Update version.py | |
run: | | |
if [ -f "client/src/bastionlab/version.py" ]; then | |
tmpfile=$(cat /tmp/version.py) | |
varfile=$(cat client/src/bastionlab/version.py) | |
if [ "$tmpfile" != "$varfile" ]; then | |
mv /tmp/version.py client/src/bastionlab/version.py | |
else | |
echo "Already up to date!" | |
exit 0 | |
fi | |
else | |
mv /tmp/version.py client/src/bastionlab/version.py | |
fi | |
- name: Commit and push env file | |
uses: devops-infra/action-commit-push@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
commit_message: Auto-sync versions |