Generate tarball automatically on new tag

This commit is contained in:
Antoine Martin 2024-09-09 19:42:13 -04:00
parent 231caa524d
commit 4fa03b9f46
Signed by: forge
GPG key ID: D62A472A4AA7D541
2 changed files with 53 additions and 31 deletions

View file

@ -6,6 +6,10 @@ on:
required: true
type: string
push:
tags:
- '*'
jobs:
build-tarball:
name: Build tarball w/ submodules
@ -24,15 +28,21 @@ jobs:
ref: ${{ inputs.ref_name }}
- name: Package build
run: |
echo "building tarball for ${{ inputs.ref_name }}"
git-archive-all --force-submodules $CI_PROJECT_NAME-${{ inputs.ref_name }}.tar.gz
if test $GITHUB_REF_NAME == "ci" ; then
CI_REF_NAME=${{ inputs.ref_name }}
else
CI_REF_NAME=$GITHUB_REF_NAME
fi
echo "CI_REF_NAME=$CI_REF_NAME" >> $GITHUB_OUTPUT
echo "building tarball for $CI_REF_NAME"
git-archive-all --force-submodules $CI_PROJECT_NAME-$CI_REF_NAME.tar.gz
echo "Generating sha512sum"
sha512sum $CI_PROJECT_NAME-${{ inputs.ref_name }}.tar.gz > $CI_PROJECT_NAME-${{ inputs.ref_name }}.tar.gz.sha512sum
sha512sum $CI_PROJECT_NAME-$CI_REF_NAME.tar.gz > $CI_PROJECT_NAME-$CI_REF_NAME.tar.gz.sha512sum
- name: Package upload
uses: forgejo/upload-artifact@v3
with:
name: tarball
path: zotero-${{ inputs.ref_name }}.*
path: zotero-*.tar*
upload-tarball:
name: Upload to generic repo
runs-on: x86_64
@ -46,5 +56,5 @@ jobs:
uses: forgejo/download-artifact@v3
- name: Package deployment
run: |
curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/zotero-${{ inputs.ref_name }}.tar.gz ${{ github.server_url }}/api/packages/mirrors/generic/zotero/${{ inputs.ref_name }}/zotero-${{ inputs.ref_name}}.tar.gz
curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/zotero-${{ inputs.ref_name }}.tar.gz.sha512sum ${{ github.server_url }}/api/packages/mirrors/generic/zotero/${{ inputs.ref_name }}/zotero-${{ inputs.ref_name}}.tar.gz.sha512sum
curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/zotero-*.tar.gz ${{ github.server_url }}/api/packages/mirrors/generic/zotero/$CI_REF_NAME/zotero-$CI_REF_NAME.tar.gz
curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/zotero-*.tar.gz.sha512sum ${{ github.server_url }}/api/packages/mirrors/generic/zotero/$CI_REF_NAME/zotero-$CI_REF_NAME.tar.gz.sha512sum

View file

@ -4,35 +4,47 @@ on:
schedule:
- cron: '@hourly'
push:
branches:
- 'main'
jobs:
mirror:
name: Pull from upstream
runs-on: x86_64
container:
image: 'docker.io/node:20-bookworm'
image: alpine:latest
env:
upstream: https://github.com/zotero/zotero
tags: '7.*'
steps:
- name: git mirror branches {v*/,}main & tags
- name: Environment setup
run: apk add grep git sed coreutils bash nodejs
- name: Fetch destination
uses: actions/checkout@v4
with:
fetch_depth: 1
ref: ci
token: ${{ secrets.CODE_FORGEJO_TOKEN }}
- name: Missing tag detecting
run: |
git init --bare .
git remote add origin https://github.com/zotero/zotero.git
git fetch origin refs/heads/main:refs/mirror/main
git ls-remote origin refs/heads/v*/main | while read sha full_ref ; do
ref=${full_ref#refs/heads/}
git fetch origin $full_ref:refs/mirror/$ref
tag=${ref%/main}
git fetch origin refs/tags/${tag}*:refs/mirror-tags/${tag}*
done
if test "${{ vars.TEST }}" != true ; then
token=${{ secrets.CODE_FORGEJO_TOKEN }}
destination=${{ vars.DESTINATION }}
owner=${{ vars.OWNER }}
else
token=${{ secrets.TEST_FORGEJO_TOKEN }}
destination=${{ vars.TEST_DESTINATION }}
owner=${{ vars.TEST_OWNER }}
fi
git push --force https://any:$token@$destination/$owner/zotero refs/mirror/*:refs/heads/* refs/mirror-tags/*:refs/tags/* --tags
git ls-remote $upstream "refs/tags/$tags" | grep -v '{' | sed 's|.*/||' > upstream_tags
git ls-remote ${{ github.server_url}}/${{ github.repository }} "refs/tags/$tags" | grep -v '{' | sed 's|.*/||' > destination_tags
cat upstream_tags destination_tags | tr ' ' '\n' | sort | uniq -u > missing_tags
echo "Missing tags:"
cat missing_tags
- name: Missing tag fetch
run: |
git remote add upstream $upstream
while read tag; do
git fetch upstream tag $tag --no-tags
done < missing_tags
- name: Packaging workflow injection
run: |
while read tag; do
git checkout $tag
git tag -d $tag
git checkout ci -- ./.forgejo
git config user.name "forgejo-actions[bot]"
git config user.email "dev@ayakael.net"
git commit -m 'Inject custom workflow'
git tag -a $tag -m $tag
done < missing_tags
- name: Push to destination
run: git push --force origin refs/tags/*:refs/tags/* --tags