-
Notifications
You must be signed in to change notification settings - Fork 14
143 lines (121 loc) · 5.69 KB
/
mirror.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Mirror from SVN
on:
push:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
schedule:
- cron: '10 */10 * * *' # every 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 mirror config branch
uses: actions/[email protected]
- name: Get current date as seconds
id: get-date
run: |
echo "timestamp=$(/bin/date -u "+%Y%m%d%H" )" >> $GITHUB_OUTPUT
shell: bash
- name: generate merged authors file
run: |
ls -RLa ${GITHUB_WORKSPACE}
cd /tmp
mkdir -p ${GITHUB_WORKSPACE}/authors
svn log https://svn.fhem.de/fhem --xml --quiet | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = $1 <>/' > ${GITHUB_WORKSPACE}/authors_svn.txt;
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;
- name: create tmpfs for svn repo
run: |
mkdir -p ./src/fhem-mirror
sudo mount -t tmpfs -o size=3G tmpfs ./src/fhem-mirror
- 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 weneed only the last one and it takes 7 days until they are deleted
id: cache-fhem
uses: actions/[email protected]
with:
path: ./src/fhem-mirror/.git
key: ${{ runner.os }}-fhemsvndir-${{ steps.get-date.outputs.timestamp }}
restore-keys: |
${{ runner.os }}-fhemsvndir-
- name: list filesystem
run: |
df -h ./src/fhem-mirror
- name: clean cache
env:
Clean_Cache: ${{ secrets.CLEANCACHE }}
if: "${{ env.Clean_Cache == 'true' }}"
run: |
rm -r ./src/fhem-mirror/.git
#- name: 'Tar files'
# run: tar -cvf ${GITHUB_WORKSPACE}/svnMirror.tar ./src/fhem-mirror/
#- uses: actions/upload-artifact@v2
# with:
# name: mirror-artifact
# path: ./svnMirror.tar
- name: init mirror repository if it is not already a mirror
timeout-minutes: 1800
run: |
if [[ ! -d "${GITHUB_WORKSPACE}/src/fhem-mirror/.git" ]]; then
git init "${GITHUB_WORKSPACE}/src/fhem-mirror" ;
cd "${GITHUB_WORKSPACE}/src/fhem-mirror";
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" ;
git config --replace-all svn.authorsfile "${GITHUB_WORKSPACE}/authors/authors_merged.txt" ;
# Run extra fetches after init, go pick up some base refs for the cache on first run only!
timeout 900 git svn -q fetch || timeout 900 git svn -q fetch || timeout 900 git svn -q fetch || true
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 "SVN_FETCH_STATUS=incomplete" >> $GITHUB_OUTPUT
cd "${GITHUB_WORKSPACE}/src/fhem-mirror";
RET=0
timeout 1800 git svn -q --log-window-size=5000 fetch || timeout 1500 git svn -q --log-window-size=5000 fetch || RET=$?;
if [[ $RET == 0 ]]; then
git switch master
git config --global user.email "[email protected]"
git config --global user.name "Github Actions"
git reset --hard "remotes/svn/trunk"
echo "SVN_FETCH_STATUS=complete" >> $GITHUB_OUTPUT
elif [[ $RET != 124 ]]; then
echo "SVN_FETCH_STATUS=error" >> $GITHUB_OUTPUT
fi
- name: Verify no fetch error state
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'error' }}
run: |
echo "A permanent error occured"
exit 1
- 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
- name: push tags and commits into master branch (force)
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
working-directory: ./src/fhem-mirror
run: |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} || git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git fetch --unshallow || true
git push origin master --force --tags