From 263b024ade1227062aa68f0507c90f067cc83234 Mon Sep 17 00:00:00 2001 From: iwishiwasaneagle Date: Tue, 7 Nov 2023 16:37:10 +0000 Subject: [PATCH] feat: move to all encompassing CI rather than depending on github to schedule on tag push --- .github/workflows/create-tag.yml | 44 ------------------- .github/workflows/publish.yml | 72 +++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/create-tag.yml diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml deleted file mode 100644 index 43a4455..0000000 --- a/.github/workflows/create-tag.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Create tag - -on: - workflow_dispatch: - schedule: - # * is a special character in YAML so you have to quote this string - - cron: '0 0 * * *' - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Should it run? - id: skip - run: | - PREVTAGCOMMIT="$(git tag --sort=creatordate | tail -n1 | awk -F'-' '{print $4}')" - CURRENTCOMMIT="$(git rev-parse --short HEAD)" - if [ "$PREVTAGCOMMIT" == "$CURRENTCOMMIT" ]; then - echo "Tags are the same ($PREVTAGCOMMIT != $CURRENTCOMMIT), skipping future steps" - echo "::set-output name=skip::true" - else - echo "Tags are not the same ($PREVTAGCOMMIT != $CURRENTCOMMIT). Continuing." - echo "::set-output name=skip::false" - fi - - - name: Set tag - id: create-tag-name - if: steps.skip.outputs.skip == 'false' - run: | - v=${GITHUB_REF##*/} - echo "Version: $v" - echo "::set-output name=tag::$(date '+%F')-$(git rev-parse --short HEAD)" - - - name: Tag commit - if: steps.skip.outputs.skip == 'false' - uses: tvdias/github-tagger@v0.0.2 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" - tag: ${{ steps.create-tag-name.outputs.tag }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b39d939..eb0cb30 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,31 +1,63 @@ -name: Publish +name: Create tag on: workflow_dispatch: - push: - tags: - - "*" + schedule: + # * is a special character in YAML so you have to quote this string + - cron: "0 0 * * *" jobs: - setup-envs: - name: Generate data for release - runs-on: ubuntu-20.04 - if: + create-tag: + name: Create tag if new commit + runs-on: ubuntu-latest outputs: - release_body: ${{ steps.release.outputs.release_body }} - tag-name: ${{ steps.create-tag-name.outputs.tag }} + skip: ${{ steps.skip.outputs.skip }} + tag: ${{ steps.create-tag-name.outputs.tag }} steps: - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Should it run? + id: skip + run: | + PREVTAGCOMMIT="$(git tag --sort=creatordate | tail -n1 | awk -F'-' '{print $4}')" + CURRENTCOMMIT="$(git rev-parse --short HEAD)" + if [ "$PREVTAGCOMMIT" == "$CURRENTCOMMIT" ]; then + echo "Tags are the same ($PREVTAGCOMMIT != $CURRENTCOMMIT), skipping future steps" + echo "skip=true" >> $GITHUB_OUTPUT + else + echo "Tags are not the same ($PREVTAGCOMMIT != $CURRENTCOMMIT). Continuing." + echo "skip=false" >> $GITHUB_OUTPUT + fi + - name: Set tag id: create-tag-name + if: steps.skip.outputs.skip == 'false' run: | v=${GITHUB_REF##*/} echo "Version: $v" - echo "::set-output name=tag::$v" + echo "tag=$(date '+%F')-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Tag commit + if: steps.skip.outputs.skip == 'false' && !env.ACT + uses: tvdias/github-tagger@v0.0.2 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + tag: ${{ steps.create-tag-name.outputs.tag }} + + setup-envs: + name: Generate data for release + runs-on: ubuntu-latest + needs: create-tag + if: needs.create-tag.outputs.skip == 'false' + outputs: + release_body: ${{ steps.release.outputs.release_body }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Generate latest changelog uses: orhun/git-cliff-action@v2 @@ -44,12 +76,12 @@ jobs: r="$(printf "$r" | tail -n +3)" r="${r//'%'/'%25'}" r="${r//$'\n'/'%0A'}" - r="${r//$'\r'/'%0D'}" - echo "::set-output name=release_body::$r" - + r="${r//$'\r'/ && build: name: Build document runs-on: ubuntu-latest + needs: [create-tag, setup-envs] + if: needs.create-tag.outputs.skip == 'false' steps: - uses: actions/checkout@v4 @@ -79,9 +111,9 @@ jobs: publish-github: name: Publish on GitHub - needs: [setup-envs, build] - runs-on: ubuntu-20.04 - + runs-on: ubuntu-latest + needs: [create-tag, setup-envs, build] + if: needs.create-tag.outputs.skip == 'false' && !env.ACT steps: - name: Checkout uses: actions/checkout@v4 @@ -99,5 +131,5 @@ jobs: tag: ${{ github.ref }} file: ${{steps.download.outputs.download-path}}/main.pdf asset_name: $tag.pdf - release_name: "${{needs.setup-envs.outputs.tag-name}}" + release_name: "${{ needs.create-tag.outputs.tag }}" body: "${{ needs.setup-envs.outputs.release_body }}"