Skip to content

Commit

Permalink
Add GitHub Actions workflow to trigger METplus testing workflow (#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemccabe authored Jan 5, 2022
1 parent 49fb555 commit e900334
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/jobs/build_and_push_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /bin/bash

# utility function to run command get log the time it took to run
function time_command {
local start_seconds=$SECONDS
echo "RUNNING: $*"
"$@"
local error=$?

local duration=$(( SECONDS - start_seconds ))
echo "TIMING: Command took `printf '%02d' $(($duration / 60))`:`printf '%02d' $(($duration % 60))` (MM:SS): '$*'"
if [ ${error} -ne 0 ]; then
echo "ERROR: '$*' exited with status = ${error}"
fi
return $error
}

prefix=refs/heads/
branch_name=${GITHUB_REF#"$prefix"}
DOCKERHUB_TAG=dtcenter/met:${branch_name}

DOCKERFILE_DIR=${GITHUB_WORKSPACE}/scripts/docker

echo "::group::Docker Build Command"
time_command docker build -t ${DOCKERHUB_TAG} \
--build-arg SOURCE_BRANCH=$branch_name \
$DOCKERFILE_DIR
echo "::endgroup::"

# skip docker push if credentials are not set
if [ -z ${DOCKER_USERNAME+x} ] || [ -z ${DOCKER_PASSWORD+x} ]; then
echo "DockerHub credentials not set. Skipping docker push"
exit 0
fi

echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin

echo "::group::Docker Push Command"
time_command docker push ${DOCKERHUB_TAG}
echo "::endgroup::"
45 changes: 45 additions & 0 deletions .github/workflows/build_docker_and_trigger_metplus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build Docker Image and Trigger METplus Workflow

on:
push:
branches:
- develop
paths-ignore:
- 'met/docs/**'

jobs:
build_met_docker:
name: Handle Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build and Push Docker Image
run: .github/jobs/build_and_push_docker_image.sh
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
trigger_metplus:
name: Trigger METplus testing workflow
runs-on: ubuntu-latest
needs: build_met_docker
steps:
- name: Print GitHub values for reference
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/github-script@v5
with:
github-token: ${{ secrets.METPLUS_BOT_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'dtcenter',
repo: 'METplus',
workflow_id: 'testing.yml',
ref: 'develop',
inputs: {
repo_name: '${{ github.repository }}',
docker_tag: '${{ github.ref }}',
actor: '${{ github.actor }}',
commit: '${{ github.sha }}'
},
});
1 change: 1 addition & 0 deletions met/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bin
share
Makefile
Makefile.in
make.log

# tilda files generated by emacs
*~
Expand Down

0 comments on commit e900334

Please sign in to comment.