mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +00:00
bbd28f38c3
add file via action instead of cli commands
136 lines
5.1 KiB
YAML
136 lines
5.1 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: checkout main branch
|
|
uses: actions/checkout@v2.4.0
|
|
|
|
- name: Get current date as seconds
|
|
id: get-date
|
|
run: |
|
|
echo "::set-output name=seconds::$(/bin/date -u "+%s")"
|
|
echo "::set-output name=timestamp::$(/bin/date -u'+%Y%m%d_%H')"
|
|
shell: bash
|
|
|
|
- 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_svn.txt;
|
|
cat ${GITHUB_WORKSPACE}/authors/authors.txt ${GITHUB_WORKSPACE}/authors_svn.txt | sort -u -k1,1 > ${GITHUB_WORKSPACE}/authors_merged.txt;
|
|
ls -la ${GITHUB_WORKSPACE}/authors_merged.txt;
|
|
|
|
- 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
|
|
key: ${{ runner.os }}-fhemsvnmirror-${{ steps.get-date.outputs.timestamp }}
|
|
restore-keys: |
|
|
${{ runner.os }}-fhemsvnmirror-
|
|
|
|
- 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 --prefix=svn/ --no-metadata https://svn.fhem.de/fhem ;
|
|
git config --add svn-remote.svn.preserve-empty-dirs "true" ;
|
|
git config --add svn-remote.svn.placeholder-filename ".gitkeep" ;
|
|
git config --add svn.authorsfile "${GITHUB_WORKSPACE}/authors_merged.txt" ;
|
|
# Run extra fetches after init, go pick up some base refs for the cache on first run only!
|
|
timeout 300 git svn -q fetch || timeout 300 git svn -q fetch || timeout 300 git svn -q fetch || true
|
|
else
|
|
echo "Current .git/config file content:";
|
|
cat ${GITHUB_WORKSPACE}/src/fhem-mirror/.git/config;
|
|
fi
|
|
|
|
- name: Copy Workflow Files to target
|
|
run: |
|
|
cp -R ${GITHUB_WORKSPACE}/.github ./src/fhem-mirror
|
|
|
|
|
|
- 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
|
|
timeout 1200 git svn -q fetch || timeout 120 git svn -q fetch || RET=$?; # Limit each run to 20 minutes to not overload fhem.de servers and build cache in chunks
|
|
if [[ $RET == 0 ]]; then
|
|
git checkout -f "master"
|
|
git rebase "remotes/svn/trunk"
|
|
git add .github/* && git commit -m "add workflow files"
|
|
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
|
|
|
|
- name: Commit changes
|
|
uses: EndBug/add-and-commit@v7
|
|
with:
|
|
message: 'add workflow file'
|
|
cwd: './src/fhem-mirror'
|
|
add: '.github/*'
|
|
branch: master
|
|
pull: 'NO-PULL'
|
|
push: false
|
|
|
|
# - name: Recreate tags from svn
|
|
# run: |
|
|
# for tag in `git branch -r | grep "tags/" | sed 's/ tags\///'`; do
|
|
# git tag -a -m"Converting SVN tags" $tag refs/remotes/$tag
|
|
# 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: ${{ secrets.GITHUB_TOKEN }}
|
|
branch: main
|
|
directory: ./src/fhem-mirror
|
|
force: true
|
|
tags: true
|