mirror of
https://github.com/cupcakearmy/gitea-sync.git
synced 2025-04-09 18:22:58 +00:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
696aeaef13 | |||
d1546f648b | |||
4ce1cca034 | |||
11ea8f8084 | |||
c03e112134 | |||
|
0cc2a1ff9e | ||
|
9ccf8b2c9a | ||
|
1092dca38a | ||
|
5ab4af8515 | ||
|
deb6ababeb | ||
936dc72804 | |||
2e34bf8ca0 |
11
.github/dependabot.yml
vendored
Normal file
11
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# To get started with Dependabot version updates, you'll need to specify which
|
||||||
|
# package ecosystems to update and where the package manifests are located.
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
12
.github/workflows/docker.yaml
vendored
12
.github/workflows/docker.yaml
vendored
@ -9,15 +9,15 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v3
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
with:
|
||||||
install: true
|
install: true
|
||||||
|
|
||||||
- name: Docker Labels
|
- name: Docker Labels
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v4
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
cupcakearmy/gitea-sync
|
cupcakearmy/gitea-sync
|
||||||
@ -30,19 +30,19 @@ jobs:
|
|||||||
type=semver,pattern={{major}}
|
type=semver,pattern={{major}}
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_TOKEN }}
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
# - name: Log in to the Container registry
|
# - name: Log in to the Container registry
|
||||||
# uses: docker/login-action@v2
|
# uses: docker/login-action@v3
|
||||||
# with:
|
# with:
|
||||||
# registry: ghcr.io
|
# registry: ghcr.io
|
||||||
# username: ${{ github.actor }}
|
# username: ${{ github.actor }}
|
||||||
# password: ${{ secrets.GITHUB_TOKEN }}
|
# password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
|
@ -33,6 +33,12 @@ GITEA_TOKEN=
|
|||||||
|
|
||||||
# Cron schedule
|
# Cron schedule
|
||||||
CRON="0 */2 * * *"
|
CRON="0 */2 * * *"
|
||||||
|
|
||||||
|
# Debug level
|
||||||
|
DEBUG_LEVEL=debug
|
||||||
|
|
||||||
|
# Only run one, skip cron and exit
|
||||||
|
RUN_ONCE=1
|
||||||
```
|
```
|
||||||
|
|
||||||
## Known limitations
|
## Known limitations
|
||||||
|
@ -35,5 +35,6 @@ export const Config = {
|
|||||||
token: simple('GITEA_TOKEN'),
|
token: simple('GITEA_TOKEN'),
|
||||||
},
|
},
|
||||||
cron: getEnv('CRON', '0 */2 * * *'),
|
cron: getEnv('CRON', '0 */2 * * *'),
|
||||||
|
runOnce: getEnv('RUN_ONCE', false, Boolean),
|
||||||
version: getEnv('npm_package_version', 'unknown'),
|
version: getEnv('npm_package_version', 'unknown'),
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,14 @@ export async function sync() {
|
|||||||
const toSync = await githubRepos()
|
const toSync = await githubRepos()
|
||||||
l.debug('loaded repos', { remote: toSync.length, local: syncedRepos.length })
|
l.debug('loaded repos', { remote: toSync.length, local: syncedRepos.length })
|
||||||
|
|
||||||
|
// List of all the repos in gitea, that are not on github
|
||||||
|
const notInSource = new Set(syncedRepos.map((r) => r.name))
|
||||||
|
|
||||||
for (const repo of toSync) {
|
for (const repo of toSync) {
|
||||||
const lr = l.child({ repo: repo.name })
|
const lr = l.child({ repo: repo.name })
|
||||||
const sameName = syncedRepos.find((r) => r.name === repo.name || r.original_url === repo.clone_url)
|
const sameName = syncedRepos.find((r) => r.name === repo.name || r.original_url === repo.clone_url)
|
||||||
if (sameName) {
|
if (sameName) {
|
||||||
|
notInSource.delete(sameName.name)
|
||||||
if (sameName.original_url === repo.clone_url) {
|
if (sameName.original_url === repo.clone_url) {
|
||||||
if (sameName.private === repo.private) logger.info('Already synced, skipping', { name: repo.name })
|
if (sameName.private === repo.private) logger.info('Already synced, skipping', { name: repo.name })
|
||||||
else {
|
else {
|
||||||
@ -52,6 +56,9 @@ export async function sync() {
|
|||||||
await mirror(options)
|
await mirror(options)
|
||||||
lr.info('mirrored repository')
|
lr.info('mirrored repository')
|
||||||
}
|
}
|
||||||
|
if (notInSource.size) {
|
||||||
|
l.info(`Found ${notInSource.size} surplus repositories in gitea`, { repos: [...notInSource] })
|
||||||
|
}
|
||||||
l.info('Finished sync')
|
l.info('Finished sync')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
l.debug(error)
|
l.debug(error)
|
||||||
|
10
src/index.ts
10
src/index.ts
@ -6,5 +6,13 @@ import { logger } from './logger.ts'
|
|||||||
|
|
||||||
logger.info(`Mirror manager - ${Config.version}`, { version: Config.version })
|
logger.info(`Mirror manager - ${Config.version}`, { version: Config.version })
|
||||||
|
|
||||||
|
Deno.addSignalListener('SIGINT', () => {
|
||||||
|
console.log('exiting...')
|
||||||
|
Deno.exit()
|
||||||
|
})
|
||||||
|
|
||||||
|
// Run on startup once, then delegate to cron
|
||||||
await sync()
|
await sync()
|
||||||
cron.schedule(Config.cron, sync)
|
if (!Config.runOnce) {
|
||||||
|
cron.schedule(Config.cron, sync)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user