Skip to content

wip4

wip4 #106

Workflow file for this run

# Copyright (C) 2020-2024 CERN and UCLouvain.
# Licensed under the GNU Lesser General Public License (version 3 or later).
# Created by: A. Valassi (Sep 2024) for the MG5aMC CUDACPP plugin.
# Further modified by: A. Valassi (2024) for the MG5aMC CUDACPP plugin.
#----------------------------------------------------------------------------------------------------------------------------------
name: Archiver
#----------------------------------------------------------------------------------------------------------------------------------
on:
push:
tags:
# Include version tags such as 'cudacpp_for3.6.0_v1.0.0' or 'cudacpp_for3.6.0_v1.0.0_test001'
# Include version tags such as 'valassi_cudacpp_for3.6.0_v1.0.0' or 'valassi_cudacpp_for3.6.0_v1.0.0_test001'
- '*cudacpp_for*_v*'
# Exclude running tags such as 'cudacpp_for3.6.0_latest'
# Exclude running tags such as 'valassi_cudacpp_for3.6.0_latest'
# See https://github.com/orgs/community/discussions/25114
- '!*cudacpp_for*_latest'
#----------------------------------------------------------------------------------------------------------------------------------
jobs:
archiver:
runs-on: ubuntu-latest
# TEMPORARY! this will change eventually...
if: |
( github.repository == 'madgraph5/madgraph4gpu' && startsWith( github.ref, 'refs/tags/cudacpp_for' ) )
|| ( github.repository == 'valassi/madgraph4gpu' && startsWith( github.ref, 'refs/tags/valassi_cudacpp_for' ) )
steps:
- name: checkout_PR
uses: actions/checkout@v4
with:
submodules: 'true'
path: branch_PR
- name: create_tarball_and_versiontxt
run: |
echo "Current directory is $(pwd)"
WORKDIR=$(pwd)
echo "WORKDIR=${WORKDIR}" >> $GITHUB_ENV
echo "WORKDIR is ${WORKDIR}"
cd branch_PR
echo "Current directory is now $(pwd)"
echo "Current branch is \"$(git branch | \grep ^* | sed 's/^* //')\""
.github/workflows/archiver.sh
mv cudacpp.tar.gz ${WORKDIR}
mv VERSION.txt ${WORKDIR}
- name: check_versiontag_and_update_versiontxt
run: |
echo "Current directory is $(pwd)"
echo "WORKDIR is ${WORKDIR}"
githubref=$${{ github.ref }}
echo "(From github.ref) githubref = ${githubref}"
tagname=${githubref#/tags/}
echo "(From github.ref) tagname = ${tagname}"
echo "TAGNAME=${tagname}" >> $GITHUB_ENV
###REPO=$${{ github.repository }}
###echo "REPO is ${REPO}" # owner is empty???
###OWNER=${REPO%/*}
###echo "OWNER is ${OWNER}" # owner is empty???
###TAGPREFIX=cudacpp_for
###if [ "${OWNER}" != "madgraph5" ]; then TAGPREFIX="${OWNER}_${TAGPREFIX}"; fi # TEMPORARY! this will change eventually...
tagsuffix=${tagname#*cudacpp_for}
TAGPREFIX=${tagname/${tagsuffix}} # determine TAGPREFIX from triggering tag because github.repository_owner is empty(???)
echo "TAGPREFIX is ${TAGPREFIX}"
# Check version tag
cudacpp_version=$(cat ${WORKDIR}/VERSION.txt | awk '/^cudacpp_version/{print $3}')
mg5_version=$(cat ${WORKDIR}/VERSION.txt | awk '/^mg5_version_current/{print $3}')
echo "(From VERSION.txt) cudacpp_version = ${cudacpp_version}"
echo "(From VERSION.txt) mg5_version_current = ${mg5_version}"
tagname_version=${TAGPREFIX}${mg5_version}_v${cudacpp_version}
echo "(From VERSION.txt) _expected_ tagname = ${tagname_version}[_...]"
if [ "${tagname/${tagname_version}}" == "${tagname}" ]; then
echo "ERROR! Invalid tagname '${tagname}' does not start with '${tagname_version}'"
exit 1 # this will cause the job to fail without running the next steps
fi
tagname_suffix="${tagname/${tagname_version}}"
if [ `python3 -c "import re; print(re.match('(|_[0-9a-z]+)$','${tagsuffix}') is not None)"` == "False" ]; then
echo "ERROR! Invalid tagname '${tagname}' (valid format is '${tagname_version}[_txt]' where txt only contains letters or digits)"
exit 1 # this will cause the job to fail without running the next steps
fi
echo "OK! Tagname '${tagname}' respects the expected format"
tagname_latest=${TAGPREFIX}${mg5_version}_latest
echo "TAGNAME_LATEST=${tagname_latest}" >> $GITHUB_ENV
# Update VERSION.txt
echo "" >> ${WORKDIR}/VERSION.txt
echo "VERSION TAG: ${tagname}" >> ${WORKDIR}/VERSION.txt
echo "RUNNING TAG: ${tagname_latest}" >> ${WORKDIR}/VERSION.txt
# Release notes for the version tag
echo "Version tag ${tagname}" > ${WORKDIR}/versiontag.txt
echo "" >> ${WORKDIR}/versiontag.txt
echo "---" >> ${WORKDIR}/versiontag.txt
echo "" >> ${WORKDIR}/versiontag.txt
cat ${WORKDIR}/VERSION.txt | egrep '^(commit|TARBALL) ' >> ${WORKDIR}/versiontag.txt
- name: delete_versiontag_releaseonly
# See https://cli.github.com/manual/gh_release_delete
# See https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/using-github-cli-in-workflows
run: |
echo "Current directory is $(pwd)"
cd branch_PR
echo "Current directory is now $(pwd)"
echo "Current branch is \"$(git branch | \grep ^* | sed 's/^* //')\""
echo "Retrieve release ${{ env.TAGNAME }}"
python3 -c 'print("-"*132)'
if gh release view ${{ env.TAGNAME }}; then
python3 -c 'print("-"*132)'
echo "Delete release ${{ env.TAGNAME }}"
gh release delete ${{ env.TAGNAME }} -y
else
python3 -c 'print("-"*132)'
echo "Release ${{ env.TAGNAME }} does not exist"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: delete_runningtag_releaseandtag
# See https://cli.github.com/manual/gh_release_delete
# See https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/using-github-cli-in-workflows
run: |
echo "Current directory is $(pwd)"
cd branch_PR
echo "Current directory is now $(pwd)"
echo "Current branch is \"$(git branch | \grep ^* | sed 's/^* //')\""
echo "Retrieve release ${{ env.TAGNAME_LATEST }}"
python3 -c 'print("-"*132)'
if gh release view ${{ env.TAGNAME_LATEST }}; then
python3 -c 'print("-"*132)'
echo "Delete release ${{ env.TAGNAME_LATEST }} and the associated tag"
gh release delete ${{ env.TAGNAME_LATEST }} -y --cleanup-tag
else
python3 -c 'print("-"*132)'
echo "Release ${{ env.TAGNAME_LATEST }} does not exist"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: create_runningtag
run: |
echo "Current directory is $(pwd)"
echo "WORKDIR is ${WORKDIR}"
cd branch_PR
echo "Current directory is now $(pwd)"
echo "Current branch is \"$(git branch | \grep ^* | sed 's/^* //')\""
tagname=${TAGNAME}
echo "(From GITHUB_ENV) tagname = ${tagname}"
tagname_latest=${TAGNAME_LATEST}
echo "(From GITHUB_ENV) tagname_latest = ${tagname_latest}"
commit=$(cat ${WORKDIR}/VERSION.txt | awk '/^commit/{print $2}')
echo "(From VERSION.txt) commit = ${commit}"
# Create running tag
git config user.name github-actions
git config user.email [email protected]
echo "INFO: create running tag ${tagname_latest}"
git tag -f ${tagname_latest} ${commit} -m "Running tag ${tagname_latest}"
git push -f --tags
# Release notes for the running tag
echo "Running tag ${tagname_latest}" > ${WORKDIR}/runningtag.txt
echo "This is equivalent to version tag ${tagname}" >> ${WORKDIR}/runningtag.txt
echo "" >> ${WORKDIR}/runningtag.txt
echo "---" >> ${WORKDIR}/runningtag.txt
echo "" >> ${WORKDIR}/runningtag.txt
cat ${WORKDIR}/VERSION.txt | egrep '^(commit|TARBALL) ' >> ${WORKDIR}/runningtag.txt
- name: release_versiontag
# See https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.TAGNAME }}
body_path: versiontag.txt
# Previous attempt to upload files from ${HOME}/VERSION.txt and ${HOME}/cudacpp.tar.gz failed
# The current implementation uploads files from the default ${WORKDIR} (without giving the explicit full path)
files: |
cudacpp.tar.gz
VERSION.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: release_runningtag
# See https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.TAGNAME_LATEST }}
tag_name: refs/tags/${{ env.TAGNAME_LATEST }}
body_path: runningtag.txt
# Previous attempt to upload files from ${HOME}/VERSION.txt and ${HOME}/cudacpp.tar.gz failed
# The current implementation uploads files from the default ${WORKDIR} (without giving the explicit full path)
files: |
cudacpp.tar.gz
VERSION.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: create_infodat
run: |
echo "Current directory is $(pwd)"
echo "WORKDIR is ${WORKDIR}"
cd branch_PR
echo "Current directory is now $(pwd)"
echo "Current branch is \"$(git branch | \grep ^* | sed 's/^* //')\""
REPO=$${{ github.repository }}
echo "REPO is ${REPO}"
python3 .github/workflows/archiver.py ${REPO} version_info.dat
mv version_info.dat ${WORKDIR}
echo "Created version_info.dat"
python3 -c 'print("-"*132)'
cat ${WORKDIR}/version_info.dat
- name: checkout_INFO
uses: actions/checkout@v4
with:
ref: INFO
path: branch_INFO
- name: commit_infodat
run: |
echo "Current directory is $(pwd)"
echo "WORKDIR is ${WORKDIR}"
cd branch_INFO
echo "Current directory is now $(pwd)"
echo "Current branch is \"$(git branch | \grep ^* | sed 's/^* //')\""
mv ${WORKDIR}/version_info.dat .
git config user.name github-actions
git config user.email [email protected]
if [ -z "$(git status --porcelain version_info.dat)" ]; then
echo "No changes detected in version_info.dat: nothing to commit"
else
echo "Commit and push version_info.dat"
echo "Update version_info.dat" > msg.txt
echo "" >> msg.txt
git diff version_info.dat | tail --lines=+6 >> msg.txt
git commit -F msg.txt version_info.dat
git push
fi
#----------------------------------------------------------------------------------------------------------------------------------