From 1742f83b8ea390a66870750e4f301d17e8794275 Mon Sep 17 00:00:00 2001 From: Haruue Date: Sat, 18 May 2024 17:13:27 +0800 Subject: [PATCH] ci: create release tags for core/ and extras/ --- .github/workflows/autotag.yaml | 104 +++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 .github/workflows/autotag.yaml diff --git a/.github/workflows/autotag.yaml b/.github/workflows/autotag.yaml new file mode 100644 index 0000000000..a066a74b51 --- /dev/null +++ b/.github/workflows/autotag.yaml @@ -0,0 +1,104 @@ +name: "Create release tags for nested modules" + +on: + push: + tags: + - app/v*.*.* + +permissions: + contents: write + +jobs: + tag: + name: "Create tags" + runs-on: ubuntu-latest + steps: + - name: "Extract tagbase" + id: extract_tagbase + uses: actions/github-script@v7 + with: + script: | + const ref = context.ref; + core.info(`context.ref: ${ref}`); + const refPrefix = 'refs/tags/app/'; + if (!ref.startsWith(refPrefix)) { + core.setFailed(`context.ref does not start with ${refPrefix}: ${ref}`); + return; + } + const tagbase = ref.slice(refPrefix.length); + core.info(`tagbase: ${tagbase}`); + core.setOutput('tagbase', tagbase); + + - name: "Tagging core/*" + uses: actions/github-script@v7 + env: + INPUT_TAGPREFIX: "core/" + INPUT_TAGBASE: ${{ steps.extract_tagbase.outputs.tagbase }} + with: + script: | + const tagbase = core.getInput('tagbase', { required: true }); + const tagprefix = core.getInput('tagprefix', { required: true }); + const refname = `tags/${tagprefix}${tagbase}`; + core.info(`creating ref ${refname}`); + try { + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/${refname}`, + sha: context.sha + }); + core.info(`created ref ${refname}`); + return; + } catch (error) { + core.info(`failed to create ref ${refname}: ${error}`); + } + core.info(`updating ref ${refname}`) + try { + await github.rest.git.updateRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: refname, + sha: context.sha + }); + core.info(`updated ref ${refname}`); + return; + } catch (error) { + core.setFailed(`failed to update ref ${refname}: ${error}`); + } + + - name: "Tagging extras/*" + uses: actions/github-script@v7 + env: + INPUT_TAGPREFIX: "extras/" + INPUT_TAGBASE: ${{ steps.extract_tagbase.outputs.tagbase }} + with: + script: | + const tagbase = core.getInput('tagbase', { required: true }); + const tagprefix = core.getInput('tagprefix', { required: true }); + const refname = `tags/${tagprefix}${tagbase}`; + core.info(`creating ref ${refname}`); + try { + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/${refname}`, + sha: context.sha + }); + core.info(`created ref ${refname}`); + return; + } catch (error) { + core.info(`failed to create ref ${refname}: ${error}`); + } + core.info(`updating ref ${refname}`) + try { + await github.rest.git.updateRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: refname, + sha: context.sha + }); + core.info(`updated ref ${refname}`); + return; + } catch (error) { + core.setFailed(`failed to update ref ${refname}: ${error}`); + }