Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Try to automate some of the translation updates #87

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

glenpike
Copy link
Contributor

@glenpike glenpike commented Jul 15, 2020

Quick and dirty bash script to update the translations package for the dependent repos (not zen-platform).
Can probably be improved, so here as a draft PR

Context in here: https://github.com/CoderDojo/cp-translations/blob/master/README.md

| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[ ",^]//g')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is jq available..? I mean, you've written this now, so maybe it doesn't matter :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could use npx project-version to get the version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, okay - so found out I can do jq '.dependencies."cp-translations"' and .dependencies."cp-translations" = "$TRANSLATIONS_VERSION" - will check that out, but means adding package.json here.


function log() {
if [[ -n $1 ]];then
printf "\033[0;36m\n$1\n\033[0m"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use tput to set the colours:

# Text color variables
txtund=$(tput sgr 0 1)    # Underline
txtbld=$(tput bold)       # Bold
txtred=$(tput setaf 1)    # Red
txtgrn=$(tput setaf 2)    # Green
txtylw=$(tput setaf 3)    # Yellow
txtblu=$(tput setaf 4)    # Blue
txtpur=$(tput setaf 5)    # Purple
txtcyn=$(tput setaf 6)    # Cyan
txtwht=$(tput setaf 7)    # White
txtrst=$(tput sgr0)       # Text reset

(from SO)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting...

@@ -0,0 +1,81 @@
#! /usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to use -eu to catch commands exiting non-zero, and undefined variables.

escaped_lhs=$(printf '%s\n' "\"cp-translations\": \"^$PACKAGE_VERSION\"" | sed 's:[][\\/.^$*]:\\&:g')
escaped_rhs=$(printf '%s\n' "\"cp-translations\": \"^$TRANSLATIONS_VERSION\"" | sed 's:[\\/&]:\\&:g;$!s/$/\\/')

sed -i '' -e "s/$escaped_lhs/$escaped_rhs/g" package.json
Copy link
Member

@DanielBrierton DanielBrierton Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn.lock also needs to be updated. I think this will result in either failures when running yarn install or it will just install the old version. I don't think there's any reason why you couldn't just run yarn add cp-translations@$TRANSLATIONS_VERSION

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a possibility of running the update inside the Docker container, but outside would result in potential mismatches in yarn.lock to do with the platform right? Maybe will check / investigate, ta.

git commit -m "Update cp-translations to $TRANSLATIONS_VERSION"
git push -u origin $BRANCH
git checkout master
# git push origin --delete $BRANCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably remove these commented out lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Yeah, was in there for testing :) ]

@glenpike
Copy link
Contributor Author

Daniel B mentioned some other possible automations that may help - this can sit and wait maybe as it's not urgent.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants