diff --git a/.github/workflows/dhcr.yml b/.github/workflows/dhcr.yml deleted file mode 100644 index b63375d..0000000 --- a/.github/workflows/dhcr.yml +++ /dev/null @@ -1,68 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: publish images - -on: - push: - branches: - - main - release: - types: [published] - -env: - DOCKER_ORG: wmoim - -jobs: - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - push: - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - strategy: - matrix: - image: - - synop2bufr - - steps: - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - - - name: Docker meta - id: metadata - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.DOCKER_ORG }}/${{ matrix.image }} - tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=pep440,pattern={{version}} - - - name: Build and push - uses: docker/build-push-action@v2.7.0 - with: - context: . - file: Dockerfile - cache-from: type=gha - cache-to: type=gha,mode=max - platforms: linux/arm64, linux/amd64 - push: true - tags: ${{ steps.metadata.outputs.tags }} - labels: ${{ steps.metadata.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml deleted file mode 100644 index 1f784a5..0000000 --- a/.github/workflows/ghcr.yml +++ /dev/null @@ -1,54 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Create and publish image to GitHub Container Registry - -on: - push: - branches: - - main - -env: - REGISTRY: ghcr.io - IMAGE_NAME: synop2bufr - -jobs: - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - push: - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - - steps: - - uses: actions/checkout@v2 - - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" - - - name: Log in to registry - # This is where you will update the PAT to GHCR_BUILD_TOKEN - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin - - - name: Rename image for publication - run: | - IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - # Use Docker `latest` tag convention - [ "$VERSION" == "main" ] && VERSION=latest - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - echo FULLCONTAINERNAME=$IMAGE_ID:$VERSION >> $GITHUB_ENV - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - - - name: Push to CR - run: docker push ${{ env.FULLCONTAINERNAME }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2009b02..c531e8b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,8 +31,7 @@ jobs: python3 -m pip install --upgrade pip pip3 install https://github.com/wmo-im/csv2bufr/archive/master.zip pip3 install -r requirements.txt - pip3 install -r requirements-dev.txt - pip3 install --no-cache-dir https://github.com/wmo-im/pymetdecoder/archive/refs/tags/v0.1.1.zip + pip3 install -r requirements-dev.txt python3 setup.py install - name: run tests ⚙️ run: | diff --git a/synop2bufr/__init__.py b/synop2bufr/__init__.py index a68c370..16a2902 100644 --- a/synop2bufr/__init__.py +++ b/synop2bufr/__init__.py @@ -33,7 +33,7 @@ from pymetdecoder import synop from csv2bufr import BUFRMessage -__version__ = '0.6.2' +__version__ = '0.7.0_dev' LOGGER = logging.getLogger(__name__) @@ -1485,12 +1485,30 @@ def transform(data: str, metadata: str, year: int, error_msgs = [] continue + def truncate_to_twenty(name: str) -> str: + """ + Ensures the string is no longer than 20 characters, + which is the maximum length allowed for the station name + in the BUFR template. + + Args: + name (str): The station or site name. + + Returns: + str: This name truncated to 20 characters. + """ + if len(name) <= 20: + return name + LOGGER.info(f"Truncating station name {name} to 20 characters") + return name[:20] + # parse WSI to get sections try: wsi_series, wsi_issuer, wsi_issue_number, wsi_local = wsi.split("-") # noqa # get other required metadata - station_name = metadata_dict[wsi]["station_name"] + station_name = truncate_to_twenty( + metadata_dict[wsi]["station_name"]) latitude = metadata_dict[wsi]["latitude"] longitude = metadata_dict[wsi]["longitude"] station_height = metadata_dict[wsi]["elevation"]