From f2a896c2e52ca9961c1e4699528a7ef94b39e019 Mon Sep 17 00:00:00 2001 From: Nicolas Lemoine Date: Mon, 14 Oct 2024 10:34:25 +0200 Subject: [PATCH] feat: Add tag release workflow --- .github/workflows/release.yml | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..37a1951 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +on: + workflow_call: + +permissions: + contents: write + +jobs: + tag-release: + runs-on: ubuntu-latest + steps: + - name: Get branch names + id: branch-names + uses: tj-actions/branch-names@v8 + + - name: Checkout + if: ${{ steps.branch-names.outputs.current_branch == 'update-dependencies' }} + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Get git commit header + if: ${{ steps.branch-names.outputs.current_branch == 'update-dependencies' }} + id: commit-header + run: | + echo "commit_header=$(git show -s --format=%s)" >> $GITHUB_OUTPUT + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + cb="$(git show -s --format=%b)" + echo "commit_body<> $GITHUB_OUTPUT + + - uses: actions/github-script@v7 + if: ${{ steps.branch-names.outputs.current_branch == 'update-dependencies' }} + id: release-tag + env: + COMMIT_HEADER: ${{ steps.commit-header.outputs.commit_header }} + with: + result-encoding: string + script: | + const commitHeader = process.env.COMMIT_HEADER; + const dateRe = new RegExp(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) (0[0-9]|1[0-9]|2[1-4]):(0[0-9]|[1-5][0-9]))/); + const dateResults = dateRe.exec(commitHeader); + if (dateResults === null) { + return ''; + } + return dateResults[0].replace(/:/g, '-').replace(/ /g, '.'); + + - name: Tag + if: ${{ steps.release-tag.outputs.result != '' }} + run: | + git config --global --add safe.directory "${GITHUB_WORKSPACE}" + git config --global user.name "${GITHUB_ACTOR}" + git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" + git tag -a "${{ steps.release-tag.outputs.result }}" -m "${{ steps.release-tag.outputs.result }}" + git push origin "${{ steps.release-tag.outputs.result }}" + + - name: Create release + if: ${{ steps.release-tag.outputs.result != '' }} + uses: softprops/action-gh-release@v2 + with: + body: ${{ steps.commit-header.outputs.commit_body }} + name: ${{ steps.release-tag.outputs.result }} + tag_name: "${{ steps.release-tag.outputs.result }}"