Skip to content

Commit 383ebb1

Browse files
committed
Add a workflow to automatically generate tags
1 parent 03cceef commit 383ebb1

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "Automatically tag new version"
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
github-token:
7+
required: true
8+
9+
jobs:
10+
auto-tag-new-version:
11+
name: "Automatically tag new version"
12+
runs-on: "ubuntu-latest"
13+
steps:
14+
- name: "Checkout"
15+
uses: "actions/checkout@v4"
16+
with:
17+
fetch-depth: 0 # see https://github.com/actions/checkout/issues/1471
18+
fetch-tags: true
19+
persist-credentials: false
20+
- name: "Extract version"
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install --assume-yes --no-install-recommends --quiet pcregrep
24+
VERSION=$(pcregrep -o1 "define\s*\(\s*['\"]PLUGIN_[A-Z]+_VERSION['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)" setup.php)
25+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
26+
- name: "Check if tag exists"
27+
run: |
28+
CREATE_TAG=no
29+
if [[ ! -z "${{ env.VERSION }}" && -z "$(git tag -l ${{ env.VERSION }})" ]]; then
30+
CREATE_TAG=yes
31+
fi
32+
echo "CREATE_TAG=${CREATE_TAG}" >> $GITHUB_ENV
33+
- name: "Create release"
34+
if: ${{ env.CREATE_TAG == 'yes' }}
35+
uses: "actions/github-script@v7"
36+
with:
37+
# A PAT is required.
38+
# From https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow:
39+
# > When you use the repository's GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_TOKEN,
40+
# > with the exception of workflow_dispatch and repository_dispatch, will not create a new workflow run.
41+
# > This prevents you from accidentally creating recursive workflow runs. For example, if a workflow run pushes
42+
# > code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository
43+
# > contains a workflow configured to run when push events occur.
44+
github-token: ${{ secrets.github-token }}
45+
script: |
46+
try {
47+
github.rest.git.createRef(
48+
{
49+
ref: 'refs/tags/${{ env.VERSION }}',
50+
sha: context.sha,
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
}
54+
);
55+
} catch (error) {
56+
core.setFailed(error.message);
57+
}

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,29 @@ jobs:
3333
# otherwise, the description will be empty.
3434
release-body: ""
3535
```
36+
37+
## Automatically tag new version workflow
38+
39+
This workflow can be used to automatically create a new tag when the plugin version in its `setup` file is updated.
40+
41+
```yaml
42+
name: "Automatically tag new version"
43+
44+
on:
45+
push:
46+
branches:
47+
- "main"
48+
paths:
49+
- "setup.php"
50+
51+
jobs:
52+
auto-tag-new-version:
53+
name: "Automatically tag new version"
54+
uses: "glpi-project/plugin-release-workflows/.github/workflows/auto-tag-new-version.yml@v1"
55+
secrets:
56+
# The access token used when the new tag is pushed.
57+
# This personal access token (PAT) is required to ensure that subsequent workflows that listen
58+
# to the tag push event will be triggered.
59+
# This PAT requires the `Content: read/write` permissions.
60+
github-token: "${{ secrets.AUTOTAG_TOKEN }}"
61+
```

0 commit comments

Comments
 (0)