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 required: true
type: string type: string
push:
tags:
- '*'
jobs: jobs:
build-tarball: build-tarball:
name: Build tarball w/ submodules name: Build tarball w/ submodules
@ -24,15 +28,21 @@ jobs:
ref: ${{ inputs.ref_name }} ref: ${{ inputs.ref_name }}
- name: Package build - name: Package build
run: | run: |
echo "building tarball for ${{ inputs.ref_name }}" if test $GITHUB_REF_NAME == "ci" ; then
git-archive-all --force-submodules $CI_PROJECT_NAME-${{ inputs.ref_name }}.tar.gz 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" 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 - name: Package upload
uses: forgejo/upload-artifact@v3 uses: forgejo/upload-artifact@v3
with: with:
name: tarball name: tarball
path: zotero-${{ inputs.ref_name }}.* path: zotero-*.tar*
upload-tarball: upload-tarball:
name: Upload to generic repo name: Upload to generic repo
runs-on: x86_64 runs-on: x86_64
@ -46,5 +56,5 @@ jobs:
uses: forgejo/download-artifact@v3 uses: forgejo/download-artifact@v3
- name: Package deployment - name: Package deployment
run: | 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-*.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-${{ 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.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: schedule:
- cron: '@hourly' - cron: '@hourly'
push:
branches:
- 'main'
jobs: jobs:
mirror: mirror:
name: Pull from upstream name: Pull from upstream
runs-on: x86_64 runs-on: x86_64
container: container:
image: 'docker.io/node:20-bookworm' image: alpine:latest
env:
upstream: https://github.com/zotero/zotero
tags: '7.*'
steps: 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: | run: |
git init --bare . git ls-remote $upstream "refs/tags/$tags" | grep -v '{' | sed 's|.*/||' > upstream_tags
git remote add origin https://github.com/zotero/zotero.git git ls-remote ${{ github.server_url}}/${{ github.repository }} "refs/tags/$tags" | grep -v '{' | sed 's|.*/||' > destination_tags
git fetch origin refs/heads/main:refs/mirror/main cat upstream_tags destination_tags | tr ' ' '\n' | sort | uniq -u > missing_tags
git ls-remote origin refs/heads/v*/main | while read sha full_ref ; do echo "Missing tags:"
ref=${full_ref#refs/heads/} cat missing_tags
git fetch origin $full_ref:refs/mirror/$ref - name: Missing tag fetch
tag=${ref%/main} run: |
git fetch origin refs/tags/${tag}*:refs/mirror-tags/${tag}* git remote add upstream $upstream
done while read tag; do
if test "${{ vars.TEST }}" != true ; then git fetch upstream tag $tag --no-tags
token=${{ secrets.CODE_FORGEJO_TOKEN }} done < missing_tags
destination=${{ vars.DESTINATION }} - name: Packaging workflow injection
owner=${{ vars.OWNER }} run: |
else while read tag; do
token=${{ secrets.TEST_FORGEJO_TOKEN }} git checkout $tag
destination=${{ vars.TEST_DESTINATION }} git tag -d $tag
owner=${{ vars.TEST_OWNER }} git checkout ci -- ./.forgejo
fi git config user.name "forgejo-actions[bot]"
git push --force https://any:$token@$destination/$owner/zotero refs/mirror/*:refs/heads/* refs/mirror-tags/*:refs/tags/* --tags 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