mirror of https://github.com/fhem/fhem-mirror.git
155 lines
5.6 KiB
YAML
155 lines
5.6 KiB
YAML
name: Mirror from SVN
|
|
|
|
on:
|
|
push:
|
|
|
|
# Allows you to run this workflow manually from the Actions tab
|
|
workflow_dispatch:
|
|
|
|
schedule:
|
|
- cron: '21 */2 * * *' # every second hour to keep cache up to date
|
|
|
|
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: |
|
|
sudo apt-get remove git git-man
|
|
sudo apt-get update
|
|
sudo apt-get install git-svn --no-install-recommends
|
|
|
|
- name: checkout authors
|
|
uses: actions/checkout@v2.4.0
|
|
with:
|
|
ref: travis
|
|
path: ./authors
|
|
|
|
- name: Get current date
|
|
id: get-date
|
|
run: |
|
|
echo "::set-output name=timestamp::$(/bin/date -u "+%Y%m%d%H" )"
|
|
shell: bash
|
|
|
|
- name: Cache runners svn-2-git-fhem mirror directory
|
|
# 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 we need only the last one and it takes 7 days until they are deleted
|
|
id: cache-fhem
|
|
uses: actions/cache@v2.1.6
|
|
with:
|
|
path: |
|
|
./src/fhem-mirror/.git
|
|
key: ${{ runner.os }}-fhemsvndir-${{ steps.get-date.outputs.timestamp }}
|
|
restore-keys: |
|
|
${{ runner.os }}-fhemsvndir-
|
|
|
|
#- name: remove gitconfig
|
|
# run: |
|
|
# rm ./src/fhem-mirror/.git/config
|
|
|
|
- name: checkout main branch
|
|
uses: actions/checkout@v2.4.0
|
|
with:
|
|
path: ./src/fhem-mirror
|
|
clean: false
|
|
|
|
- name: generate merged authors file
|
|
run: |
|
|
cd /tmp
|
|
svn log https://svn.fhem.de/fhem --xml --quiet | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = $1 <>/' > ${GITHUB_WORKSPACE}/authors/authors_svn.txt;
|
|
cat ${GITHUB_WORKSPACE}/authors/authors.txt ${GITHUB_WORKSPACE}/authors/authors_svn.txt | sort -u -k1,1 > ${GITHUB_WORKSPACE}/authors/authors_merged.txt;
|
|
ls -la ${GITHUB_WORKSPACE}/authors/authors_merged.txt;
|
|
|
|
- name: fetch from svn
|
|
id: fetchsvn
|
|
timeout-minutes: 120
|
|
working-directory: ./src/fhem-mirror
|
|
run: |
|
|
echo "::group::git svn init"
|
|
git svn init --trunk=trunk --tags=tags --prefix=svn/ https://svn.fhem.de/fhem;
|
|
git config --add svn.authorsfile "${GITHUB_WORKSPACE}/authors/authors_merged.txt"
|
|
git config --add svn-remote.svn.preserve-empty-dirs "true" ;
|
|
git config --add svn-remote.svn.placeholder-filename ".gitkeep" ;
|
|
echo "Current .git/config file content:";
|
|
cat ${GITHUB_WORKSPACE}/src/fhem-mirror/.git/config;
|
|
echo "::endgroup::"
|
|
|
|
echo "::set-output name=SVN_FETCH_STATUS::incomplete"
|
|
# Run fetches after init, go pick up some base refs for the cache on first run only!
|
|
RET=124
|
|
c=1
|
|
while [ $RET -eq 124 ]; do
|
|
echo "::group::Fetch ${c}/5"
|
|
timeout 1200 git svn --log-window-size=200 -q fetch && RET=$? || true
|
|
if [ "$RET" -ne 0 ] && [ "$RET" -ne 124 ]; then
|
|
echo "::set-output name=SVN_FETCH_STATUS::error"
|
|
fi
|
|
((c++)) && ((c==6)) && break
|
|
echo "::endgroup::"
|
|
done
|
|
if [ "$RET" -eq 0 ]; then
|
|
echo "::set-output name=SVN_FETCH_STATUS::complete"
|
|
fi
|
|
|
|
# - name: Copy Workflow Files to target
|
|
# if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
|
|
# run: |
|
|
# cp -R ${GITHUB_WORKSPACE}/main/.github ./src/fhem-mirror
|
|
|
|
- name: Verify no fetch error state
|
|
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'error' }}
|
|
run: |
|
|
echo "A permanent error occured"
|
|
exit 1
|
|
|
|
- name: show gitconfig
|
|
run: |
|
|
cat ${GITHUB_WORKSPACE}/src/fhem-mirror/.git/config;
|
|
|
|
- name: Commit changes
|
|
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
|
|
uses: EndBug/add-and-commit@v7
|
|
with:
|
|
message: 'add workflow file'
|
|
cwd: './src/fhem-mirror'
|
|
add: '.github/*'
|
|
branch: main
|
|
pull: 'NO-PULL'
|
|
push: origin main --force
|
|
|
|
- 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/origin/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 -m "$BODY" $TAG_NAME $REF^ #&&\
|
|
git branch -r -d origin/tags/$BRANCH
|
|
done
|
|
|
|
# - name: Commit fetched files
|
|
# run: |
|
|
# cd "${GITHUB_WORKSPACE}/src/fhem-mirror";
|
|
# echo "Will now prepare push following directory structure to remote repo:";
|
|
# ls -la ;
|
|
# git config --add remote.origin.push 'refs/remotes/svn/trunk:refs/heads/master';
|
|
|
|
|
|
- name: Push force changes to master branch in same repo
|
|
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
|
|
uses: ad-m/github-push-action@v0.6.0
|
|
with:
|
|
github_token: ${{ github.token }}
|
|
branch: main
|
|
directory: ./src/fhem-mirror
|
|
force: true
|
|
tags: true
|