From 85a04f886c40e21ee1fa65f7e58527259aa99093 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Mon, 9 Sep 2024 19:32:32 -0400 Subject: [PATCH] Generate tarball automatically on new tag --- .forgejo/workflows/generate-tarball.yml | 29 ++++++++---- .forgejo/workflows/mirror-repository.yml | 58 +++++++++++++++--------- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/.forgejo/workflows/generate-tarball.yml b/.forgejo/workflows/generate-tarball.yml index 15a6fd2b7..4fa5ab10b 100644 --- a/.forgejo/workflows/generate-tarball.yml +++ b/.forgejo/workflows/generate-tarball.yml @@ -6,6 +6,10 @@ on: required: true type: string + push: + tags: + - '*' + jobs: build-tarball: name: Build tarball @@ -22,15 +26,21 @@ jobs: ref: ${{ inputs.ref_name }} - name: Package build run: | + 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 sed 's||' -i src/SourceBuild/Arcade/tools/SourceBuildArcadeTarball.targets export _cli_root=/usr/lib/dotnet - echo "Building dotnet-${{ inputs.ref_name }} tarball" - _InitializeDotNetCli="$_cli_root" DOTNET_INSTALL_DIR="$_cli_root" DotNetBuildFromSource=true ./build.sh /p:ArcadeBuildTarball=true /p:EnableSourceLink=false /p:CheckEolTargetFramework=false /p:TarballDir=$(pwd)/dotnet-${{ inputs.ref_name }} /p:TarballFilePath=$(pwd)/dotnet-${{ inputs.ref_name }}.tar - echo "Compressing dotnet-${{ inputs.ref_name }}.tar.xz" - xz -T0 -9 -vv -e -c > ./dotnet-${{ inputs.ref_name }}.tar.xz < ./dotnet-${{ inputs.ref_name }}.tar + echo "Building dotnet-$CI_REF_NAME tarball" + _InitializeDotNetCli="$_cli_root" DOTNET_INSTALL_DIR="$_cli_root" DotNetBuildFromSource=true ./build.sh /p:ArcadeBuildTarball=true /p:EnableSourceLink=false /p:CheckEolTargetFramework=false /p:TarballDir=$(pwd)/dotnet-$CI_REF_NAME /p:TarballFilePath=$(pwd)/dotnet-$CI_REF_NAME.tar + echo "Compressing dotnet-$CI_REF_NAME.tar.xz" + xz -T0 -9 -vv -e -c > ./dotnet-$CI_REF_NAME.tar.xz < ./dotnet-$CI_REF_NAME.tar echo "Generating sha512sum and sha256sum" - sha512sum dotnet-${{ inputs.ref_name }}.tar.xz > dotnet-${{ inputs.ref_name }}.tar.xz.sha512sum - sha256sum dotnet-${{ inputs.ref_name }}.tar.xz > dotnet-${{ inputs.ref_name }}.tar.xz.sha256sum + sha512sum dotnet-$CI_REF_NAME.tar.xz > dotnet-$CI_REF_NAME.tar.xz.sha512sum + sha256sum dotnet-$CI_REF_NAME.tar.xz > dotnet-$CI_REF_NAME.tar.xz.sha256sum - name: Package upload uses: forgejo/upload-artifact@v3 with: @@ -50,7 +60,6 @@ jobs: uses: forgejo/download-artifact@v3 - name: Package deployment run: | - find . - curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/dotnet-*.tar.xz ${{ github.server_url }}/api/packages/mirrors/generic/dotnet/${{ inputs.ref_name }}/dotnet-${{ inputs.ref_name}}.tar.xz - curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/dotnet-*.tar.xz.sha512sum ${{ github.server_url }}/api/packages/mirrors/generic/dotnet/${{ inputs.ref_name }}/dotnet-${{ inputs.ref_name}}.tar.xz.sha512sum - curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/dotnet-*.tar.xz.sha256sum ${{ github.server_url }}/api/packages/mirrors/generic/dotnet/${{ inputs.ref_name }}/dotnet-${{ inputs.ref_name}}.tar.xz.sha256sum + curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/dotnet-*.tar.xz ${{ github.server_url }}/api/packages/mirrors/generic/dotnet/$CI_REF_NAME/dotnet-$CI_REF_NAME.tar.xz + curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/dotnet-*.tar.xz.sha512sum ${{ github.server_url }}/api/packages/mirrors/generic/dotnet/$CI_REF_NAME/dotnet-$CI_REF_NAME.tar.xz.sha512sum + curl --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file ./tarball/dotnet-*.tar.xz.sha256sum ${{ github.server_url }}/api/packages/mirrors/generic/dotnet/$CI_REF_NAME/dotnet-$CI_REF_NAME.tar.xz.sha256sum diff --git a/.forgejo/workflows/mirror-repository.yml b/.forgejo/workflows/mirror-repository.yml index 50ec33eeb..b2527d56a 100644 --- a/.forgejo/workflows/mirror-repository.yml +++ b/.forgejo/workflows/mirror-repository.yml @@ -9,26 +9,42 @@ jobs: name: Pull from upstream runs-on: x86_64 container: - image: 'docker.io/node:20-bookworm' + image: alpine:latest + env: + upstream: https://github.com/dotnet/installer + tags: 'v6.0.1*' steps: - - name: git mirror branches {v*/,}* & 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/dotnet/installer - git fetch origin refs/heads/*:refs/mirror/* - git ls-remote origin refs/heads/v*/* | while read sha full_ref ; do - ref=${full_ref#refs/heads/} - git fetch origin $full_ref:refs/mirror/$ref - tag=${ref} - 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/dotnet-installer 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