Copy from SourceForge Subversion #284
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to bootstrap this action, create an empty repo with just this file and svn-authors | |
# run the action once with force parameter set to "yes" | |
# git commit -m "xxx" * && git push -f && gh workflow run -R kichik/nsis-travis copy-svn.yml -f force=yes | |
name: Copy from SourceForge Subversion | |
on: | |
workflow_dispatch: | |
inputs: | |
force: | |
description: 'Force push (CAREFUL!)' | |
options: ["no", "yes"] | |
type: choice | |
required: false | |
schedule: | |
- cron: '4 10 * * *' | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
concurrency: | |
# Concurrency group that uses the workflow name and PR number if available | |
# or commit SHA as a fallback. If a new build is triggered under that | |
# concurrency group while a previous build is running it will be canceled. | |
# Repeated pushes to a PR will cancel all previous builds, while multiple | |
# merges to main will not cancel. | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | |
cancel-in-progress: true | |
permissions: | |
contents: write # for Git to git push | |
jobs: | |
copy: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install git-svn | |
run: sudo add-apt-repository ppa:git-core/ppa && sudo apt update && sudo apt install git-svn | |
- name: Configure git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
- name: Restore cache | |
id: restore-cache | |
uses: actions/cache/restore@v3 | |
with: | |
path: | | |
svn2git | |
key: svn2git-${{ github.event.pull_request.number || github.ref_name }} | |
- name: Initial SVN clone | |
if: steps.restore-cache.outputs.cache-hit != 'true' | |
run: | | |
git config --global init.defaultBranch main | |
git svn clone -A.github/workflows/svn-authors -s https://svn.code.sf.net/p/nsis/code/NSIS svn2git | |
- name: SVN fetch | |
working-directory: svn2git | |
run: | | |
git svn fetch --fetch-all | |
git svn rebase | |
- name: SVN branches | |
working-directory: svn2git | |
run: | | |
for remote_branch in $(git branch -r | grep -v /tags/); do | |
if echo $remote_branch | grep @; then | |
echo ignoring weird branch $remote_branch | |
continue | |
fi | |
local_branch=`echo $remote_branch | cut -d / -f 2-` | |
git checkout -b "$local_branch" "$remote_branch" || git checkout "$local_branch" | |
git svn rebase | |
done | |
git checkout main # this is the default branch inside `svn2git` | |
- name: SVN tags | |
working-directory: svn2git | |
id: svn_tags | |
run: | | |
tags="" | |
git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/origin/tags \ | |
| while read BRANCH REF | |
do | |
TAG_NAME=$(echo $BRANCH | cut -d / -f 3-) | |
BODY="$(git log -1 --format=format:%B $REF)" | |
echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2 | |
if [ $(git tag -l "$TAG_NAME" 2>/dev/null) ]; then | |
echo "tag already exists" | |
else | |
git tag -a -m "$BODY" $TAG_NAME $REF^ | |
tags="${tags} ${TAG_NAME}" | |
fi | |
done | |
echo "tags=${tags}" >> ${GITHUB_OUTPUT} | |
- name: Push to GitHub | |
working-directory: svn2git | |
if: github.event_name != 'pull_request' | |
run: | | |
flags="" | |
if [[ "${{ github.event.inputs.force }}" = "yes" ]]; then | |
flags="--force" | |
fi | |
remote_repo="https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" | |
git pull "$remote_repo" main --no-rebase -X theirs | |
git push "$remote_repo" --all $flags | |
if [[ -n "${{ steps.svn_tags.outputs.tags }}" ]]; then | |
for tag in ${{ steps.svn_tags.outputs.tags }}; do | |
git push "$remote_repo" refs/tags/${tag} $flags | |
done | |
fi | |
- name: GC | |
working-directory: svn2git | |
if: always() | |
run: | | |
echo "run garbage collection so caching does not fail while files are changing" | |
git gc --auto | |
- name: Save cache | |
id: save-cache | |
uses: actions/cache/save@v3 | |
if: always() | |
with: | |
path: | | |
svn2git | |
key: svn2git-${{ github.event.pull_request.number || github.ref_name }} |