From bb9ff1dba0675c1c26b40bd0bc57afb34b7dc0ca Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Wed, 20 May 2020 14:31:30 +0200 Subject: [PATCH] Configure GitHub workflow to update currency codes Signed-off-by: Henrique Moody --- .github/workflows/update-currency-codes.yaml | 33 +++++++++++ bin/update-currency-codes | 62 +++++++++----------- 2 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/update-currency-codes.yaml diff --git a/.github/workflows/update-currency-codes.yaml b/.github/workflows/update-currency-codes.yaml new file mode 100644 index 00000000..8fda3cfe --- /dev/null +++ b/.github/workflows/update-currency-codes.yaml @@ -0,0 +1,33 @@ +name: Update currency codes + +on: + schedule: + - cron: '0 0 * * 0' + +jobs: + update-currency-codes: + name: Update currency codes + + runs-on: ubuntu-latest + + steps: + - name: Install xmlstarlet + run: sudo apt install xmlstarlet + + - name: Checkout + uses: actions/checkout@v2 + with: + ref: "2.0" + + - name: Execute script + run: bin/update-currency-codes + + - name: Create pull request + uses: peter-evans/create-pull-request@v2 + with: + committer: The Respect Panda + author: The Respect Panda + commit-message: Update list of currency codes + title: Update list of currency codes + base: "2.0" + branch: "workflows/update-currency-codes" diff --git a/bin/update-currency-codes b/bin/update-currency-codes index bf929a2d..837b3fe4 100755 --- a/bin/update-currency-codes +++ b/bin/update-currency-codes @@ -1,45 +1,39 @@ #!/usr/bin/env bash -# Usage: {script} TLD_FILENAME -# Update list of TLD +# Usage: {script} +# Update the list of currency codes set -euo pipefail declare -r IFS=$'\n' -declare -r URL="https://www.currency-iso.org/dam/downloads/lists/list_one.xml" -declare -r RULE="${1}" -declare -r TEMPORARY_XML=$(mktemp) -download_list() +declare -r LIST_URL="https://www.currency-iso.org/dam/downloads/lists/list_one.xml" +declare -r LIST_FILENAME=$(mktemp) + +declare -r RULE_FILENAME=$(dirname "${BASH_SOURCE}")/../library/Rules/CurrencyCode.php +declare -r RULE_FILENAME_TEMPORARY=$(mktemp) + +echo "- Downloading list" +curl --silent --location "${LIST_URL}" --output "${LIST_FILENAME}" + +declare -r CURRENCY_CODES_COUNT=$(grep "" "${LIST_FILENAME}" | wc --lines) + +echo "- Creating temporary file" { - echo "Downloading list from '${URL}'" - curl --silent --location "${1}" --output "${2}" -} + sed -n "/^" "${filename_xml}" | wc --lines) - local -r temporary_rule=$(mktemp) + if [[ -z "${code}" ]]; then + continue + fi - echo "Updating list in '${filename_rule}'" - { - sed -n "/^ "${RULE_FILENAME_TEMPORARY}" - if [[ -z "${code}" ]]; then - continue - fi +echo "- Updating content of '$(basename ${RULE_FILENAME})'" +mv "${RULE_FILENAME_TEMPORARY}" "${RULE_FILENAME}" - echo " '${code}', //" $(sed --regexp-extended 's, +$,,' <<< "${name}") - done | sort --unique - sed --silent '/^ \]/,/^}/p' "${filename_rule}" - } > "${temporary_rule}" - - mv "${temporary_rule}" "${filename_rule}" -} - -download_list "${URL}" "${TEMPORARY_XML}" -update_currency_codes "${RULE}" "${TEMPORARY_XML}" +echo "Finished!"