Skip to content

update logic to be able to trigger METplus testing workflow for main_… #520

update logic to be able to trigger METplus testing workflow for main_…

update logic to be able to trigger METplus testing workflow for main_… #520

name: Build Docker Image and Trigger METplus Workflow
on:
push:
branches:
- develop
- 'main_v[0-9]+.[0-9]+'
paths-ignore:
- 'docs/**'
workflow_dispatch:
env:
DOCKERHUB_REPO: dtcenter/met-dev
jobs:
build_met_docker:
name: Handle Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get branch name
id: get_branch_name
run: echo branch_name=${GITHUB_REF#refs/heads/} >> $GITHUB_OUTPUT
- name: Build Docker Image
run: .github/jobs/build_docker_image.sh
env:
SOURCE_BRANCH: ${{ steps.get_branch_name.outputs.branch_name }}-lite
MET_BASE_REPO: met-base
MET_BASE_TAG: v3.3
- name: Push Docker Image
run: .github/jobs/push_docker_image.sh
env:
SOURCE_BRANCH: ${{ steps.get_branch_name.outputs.branch_name }}-lite
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"
- name: Checkout code from this repo
uses: actions/checkout@v4
- name: Get METplus repo for component version script
uses: actions/checkout@v4
with:
repository: 'dtcenter/METplus'
ref: 'develop'
path: 'METplus'
- name: Get version from ref (branch)
- id: get_version
run: |
version=$(cut -d "/" -f3 <<< "${GITHUB_REF}")
echo "version=${version}" >> $GITHUB_OUTPUT
- id: get_metplus_branch
run: |
repo=${{ github.repository }}
repo=${repo#*/}
version=${{ steps.get_version.outputs.version }}
if [ "${version}" == "develop" ]; then
metplus_branch=develop
else
cmd="$GITHUB_WORKSPACE/METplus/metplus/component_versions.py -i ${repo} -v ${version} -o METplus -f main_v{X}.{Y}"
echo $cmd
metplus_branch=$($cmd)
fi
# if no branch can be determined, exit and error
if [ -z "${metplus_branch}" ]; then
echo "ERROR: Could not get METplus branch"
exit 1
fi
branch_exists=$(git -C $GITHUB_WORKSPACE/METplus ls-remote origin ${metplus_branch})
if [ -z "${branch_exists}" ]; then
echo "METplus branch ${metplus_branch} does not exist yet"
metplus_branch=none
fi
echo "metplus_branch=${metplus_branch}" >> $GITHUB_OUTPUT
- if: ( steps.get_metplus_branch.outputs.metplus_branch != 'none' )
run: |
metplus_branch=${{ steps.get_metplus_branch.outputs.metplus_branch }}
echo "Triggering workflow dispatch of ${metplus_branch}"
- if: ( steps.get_metplus_branch.outputs.metplus_branch != 'none' )
uses: actions/github-script@v7
with:
github-token: ${{ secrets.METPLUS_BOT_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'dtcenter',
repo: 'METplus',
workflow_id: 'testing.yml',
ref: ${{ steps.get_metplus_branch.outputs.metplus_branch }},
inputs: {
repository: '${{ github.repository }}',
ref: '${{ github.ref }}',
actor: '${{ github.actor }}',
sha: '${{ github.sha }}',
pusher_email: '${{ github.event.pusher.email }}'
},
});