2021-01-08 10:24:20 +00:00
name : Mirror from SVN
on :
push :
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch :
schedule :
2022-09-04 09:09:52 +00:00
- cron : '10 */1 * * *' # every hour to keep cache up to date
2021-01-08 10:24:20 +00:00
jobs :
# This workflow contains a single job called "build"
mirror :
# The type of runner that the job will run on
runs-on : ubuntu-latest
continue-on-error : true
steps :
- name : install git-svn package
run : |
2021-04-17 21:33:07 +00:00
sudo apt-get remove git git-man
2021-01-08 10:24:20 +00:00
sudo apt-get update
sudo apt-get install git-svn --no-install-recommends
- name : checkout mirror config branch
2022-03-02 20:13:39 +00:00
uses : actions/checkout@v3
2021-01-08 10:24:20 +00:00
- name : Get current date as seconds
id : get-date
run : |
2021-12-22 10:00:11 +00:00
echo "::set-output name=timestamp::$(/bin/date -u "+%Y%m%d%H" )"
2021-01-08 10:24:20 +00:00
shell : bash
- name : generate merged authors file
run : |
2021-12-22 10:00:11 +00:00
ls -RLa ${GITHUB_WORKSPACE}
2021-01-08 10:24:20 +00:00
cd /tmp
2021-12-22 10:00:11 +00:00
mkdir -p ${GITHUB_WORKSPACE}/authors
2021-01-08 10:24:20 +00:00
svn log https://svn.fhem.de/fhem --xml --quiet | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = $1 <>/' > ${GITHUB_WORKSPACE}/authors_svn.txt;
2021-12-22 10:00:11 +00:00
cat ${GITHUB_WORKSPACE}/authors.txt ${GITHUB_WORKSPACE}/authors_svn.txt | sort -u -k1,1 > ${GITHUB_WORKSPACE}/authors/authors_merged.txt;
ls -la ${GITHUB_WORKSPACE}/authors/authors_merged.txt;
2021-01-08 10:24:20 +00:00
- name : Cache runners svn-2-git-fhem mirror directory
2021-01-08 11:03:27 +00:00
# Some room for improvement because we create a new cache on every run where a new ref is fetched, this isn't very nice, normaly weneed only the last one and it takes 7 days until they are deleted
2021-01-08 10:24:20 +00:00
id : cache-fhem
2022-03-21 19:45:01 +00:00
uses : actions/cache@v3
2021-01-08 10:24:20 +00:00
with :
2021-12-22 10:00:11 +00:00
path : ./src/fhem-mirror/.git
key : ${{ runner.os }}-fhemsvndir-${{ steps.get-date.outputs.timestamp }}
2021-01-08 10:24:20 +00:00
restore-keys : |
2021-12-22 10:00:11 +00:00
${{ runner.os }}-fhemsvndir-
2022-02-20 20:17:29 +00:00
- name : clean cache
env :
Clean_Cache : ${{ secrets.CLEANCACHE }}
if : "${{ env.Clean_Cache == 'true' }}"
run : |
rm -r ./src/fhem-mirror/.git
2021-12-22 10:00:11 +00:00
#- name: 'Tar files'
# run: tar -cvf ${GITHUB_WORKSPACE}/svnMirror.tar ./src/fhem-mirror/
2021-01-08 10:24:20 +00:00
2021-12-22 10:00:11 +00:00
#- uses: actions/upload-artifact@v2
# with:
# name: mirror-artifact
# path: ./svnMirror.tar
2021-01-08 10:24:20 +00:00
- name : init mirror repository if it is not already a mirror
2021-01-08 10:46:56 +00:00
timeout-minutes : 1800
2021-01-08 10:24:20 +00:00
run : |
if [[ ! -d "${GITHUB_WORKSPACE}/src/fhem-mirror/.git" ]]; then
git init "${GITHUB_WORKSPACE}/src/fhem-mirror" ;
cd "${GITHUB_WORKSPACE}/src/fhem-mirror";
2021-12-22 10:00:11 +00:00
git svn init --trunk=trunk --tags=tags --prefix=svn/ https://svn.fhem.de/fhem;
git config --replace-all svn-remote.svn.preserve-empty-dirs "true" ;
git config --replace-all svn-remote.svn.placeholder-filename ".gitkeep" ;
2022-02-20 20:17:29 +00:00
git config --replace-all svn.authorsfile "${GITHUB_WORKSPACE}/authors/authors_merged.txt" ;
2021-01-08 10:46:56 +00:00
# Run extra fetches after init, go pick up some base refs for the cache on first run only!
2022-09-04 09:09:52 +00:00
timeout 900 git svn -q fetch || timeout 900 git svn -q fetch || timeout 900 git svn -q fetch || true
2021-01-08 10:24:20 +00:00
else
echo "Current .git/config file content:";
cat ${GITHUB_WORKSPACE}/src/fhem-mirror/.git/config;
fi
- name : fetch svn to git master branch
id : fetchsvn
timeout-minutes : 1800
run : |
echo "::set-output name=SVN_FETCH_STATUS::incomplete"
cd "${GITHUB_WORKSPACE}/src/fhem-mirror";
RET=0
2022-09-04 09:09:52 +00:00
timeout 1800 git svn -q --log-window-size=5000 fetch || timeout 1800 git svn -q --log-window-size=5000 fetch || timeout 1200 git svn -q --log-window-size=600 fetch || RET=$?;
2021-01-08 10:24:20 +00:00
if [[ $RET == 0 ]]; then
2021-12-22 10:00:11 +00:00
git branch -f master
git checkout master
git config --global user.email "actions@gitbhub.com"
git config --global user.name "Github Actions"
git reset --hard "remotes/svn/trunk"
2021-01-08 10:24:20 +00:00
echo "::set-output name=SVN_FETCH_STATUS::complete"
elif [[ $RET != 124 ]]; then
echo "::set-output name=SVN_FETCH_STATUS::error"
fi
- name : Verify no fetch error state
if : ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'error' }}
run : |
echo "A permanent error occured"
exit 1
2021-12-28 17:19:49 +00:00
- name : Recreate tags from svn
if : ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
working-directory : ./src/fhem-mirror
run : |
git for-each-ref --format="%(refname:lstrip=-1) %(objectname)" refs/remotes/svn/tags/FHEM_*_? \
| while read BRANCH REF
do
TAG_NAME=${BRANCH#FHEM_}
TAG_NAME=$(echo $TAG_NAME | sed 's/_/./g')
BODY="$(git log -1 --format=format:%B $REF)"
echo "branch=$BRANCH ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2
git tag -a -f -m "$BODY" $TAG_NAME $REF^
# git branch -r -d origin/tags/$BRANCH
done
2021-01-08 10:24:20 +00:00
2022-02-20 20:17:29 +00:00
- name : push tags and commits into master branch (force)
2021-01-08 10:24:20 +00:00
if : ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
2022-02-20 20:17:29 +00:00
working-directory : ./src/fhem-mirror
run : |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git fetch --unshallow || true
git push origin master --force --tags