| 1 |
# to bootstrap this action, create an empty repo with just this file and svn-authors |
| 2 |
# run the action once with force parameter set to "yes" |
| 3 |
|
| 4 |
# git commit -m "xxx" * && git push -f && gh workflow run -R kichik/nsis-travis copy-svn.yml -f force=yes |
| 5 |
|
| 6 |
name: Copy from SourceForge Subversion |
| 7 |
on: |
| 8 |
workflow_dispatch: |
| 9 |
inputs: |
| 10 |
force: |
| 11 |
description: 'Force push (CAREFUL!)' |
| 12 |
required: false |
| 13 |
schedule: |
| 14 |
- cron: '4 10 * * *' |
| 15 |
|
| 16 |
jobs: |
| 17 |
copy: |
| 18 |
runs-on: ubuntu-22.04 |
| 19 |
steps: |
| 20 |
- uses: actions/checkout@v6 |
| 21 |
|
| 22 |
- name: Install git-svn |
| 23 |
run: sudo add-apt-repository ppa:git-core/ppa && sudo apt update && sudo apt install git-svn |
| 24 |
|
| 25 |
- name: Configure git |
| 26 |
run: | |
| 27 |
git config --global user.email "[email protected]" |
| 28 |
git config --global user.name "Amir Szekely" |
| 29 |
|
| 30 |
- name: Restore cache |
| 31 |
id: restore-cache |
| 32 |
run: | |
| 33 |
if git fetch origin svn2git-cache; then |
| 34 |
git checkout svn2git-cache |
| 35 |
else |
| 36 |
git checkout --orphan svn2git-cache |
| 37 |
git rm -rf --cached . |
| 38 |
git add .github/workflows/* |
| 39 |
git commit -m "Empty cache" |
| 40 |
echo "cache-hit=false" >> $GITHUB_OUTPUT |
| 41 |
fi |
| 42 |
|
| 43 |
if [ -f svn2git-cache.tar.gz ]; then |
| 44 |
tar xzf svn2git-cache.tar.gz |
| 45 |
echo "cache-hit=true" >> $GITHUB_OUTPUT |
| 46 |
else |
| 47 |
echo "cache-hit=false" >> $GITHUB_OUTPUT |
| 48 |
fi |
| 49 |
|
| 50 |
- name: Initial SVN clone |
| 51 |
if: steps.restore-cache.outputs.cache-hit != 'true' |
| 52 |
run: | |
| 53 |
git svn clone -A.github/workflows/svn-authors -s https://svn.code.sf.net/p/nsis/code/NSIS svn2git |
| 54 |
|
| 55 |
- name: SVN fetch |
| 56 |
working-directory: svn2git |
| 57 |
run: | |
| 58 |
git svn fetch --fetch-all |
| 59 |
git svn rebase |
| 60 |
|
| 61 |
- name: SVN branches |
| 62 |
working-directory: svn2git |
| 63 |
run: | |
| 64 |
for remote_branch in $(git branch -r | grep -v /tags/); do |
| 65 |
if echo $remote_branch | grep @; then |
| 66 |
echo ignoring weird branch $remote_branch |
| 67 |
continue |
| 68 |
fi |
| 69 |
|
| 70 |
local_branch=`echo $remote_branch | cut -d / -f 2-` |
| 71 |
git checkout -b "$local_branch" "$remote_branch" || git checkout "$local_branch" |
| 72 |
git svn rebase |
| 73 |
done |
| 74 |
git checkout master |
| 75 |
|
| 76 |
- name: SVN tags |
| 77 |
working-directory: svn2git |
| 78 |
run: | |
| 79 |
git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/origin/tags \ |
| 80 |
| while read BRANCH REF |
| 81 |
do |
| 82 |
TAG_NAME=`echo $BRANCH | cut -d / -f 3-` |
| 83 |
BODY="$(git log -1 --format=format:%B $REF)" |
| 84 |
echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2 |
| 85 |
if [ $(git tag -l "$TAG_NAME") ]; then |
| 86 |
echo tag already exists |
| 87 |
else |
| 88 |
git tag -a -m "$BODY" $TAG_NAME $REF^ |
| 89 |
fi |
| 90 |
done |
| 91 |
|
| 92 |
- name: Setup GitHub access |
| 93 |
env: |
| 94 |
SSH_KEY: ${{ secrets.SSH_KEY }} |
| 95 |
run: | |
| 96 |
mkdir -p ~/.ssh |
| 97 |
touch ~/.ssh/id_ed25519 |
| 98 |
chmod 600 ~/.ssh/id_ed25519 |
| 99 |
echo "$SSH_KEY" >> ~/.ssh/id_ed25519 |
| 100 |
|
| 101 |
- name: Push to GitHub |
| 102 |
working-directory: svn2git |
| 103 |
run: | |
| 104 |
flags="" |
| 105 |
if [[ "${{ github.event.inputs.force }}" = "yes" ]]; then |
| 106 |
flags="--force" |
| 107 |
fi |
| 108 |
remote_repo="[email protected]:${GITHUB_REPOSITORY}.git" |
| 109 |
git push "$remote_repo" --all $flags |
| 110 |
git push "$remote_repo" --tags $flags |
| 111 |
|
| 112 |
- name: GC |
| 113 |
working-directory: svn2git |
| 114 |
run: | |
| 115 |
echo run garbage collection so caching does not fail while files are changing |
| 116 |
git gc --auto |
| 117 |
|
| 118 |
- name: Save cache |
| 119 |
run: | |
| 120 |
rm -f svn2git-cache.tar.gz |
| 121 |
tar czf svn2git-cache.tar.gz svn2git |
| 122 |
git add svn2git-cache.tar.gz |
| 123 |
cp svn2git/.github/workflows/* .github/workflows/ |
| 124 |
git add .github/workflows/* |
| 125 |
git commit --amend -m "update cache" svn2git-cache.tar.gz |
| 126 |
git push --force [email protected]:${GITHUB_REPOSITORY}.git svn2git-cache |