@@ -13,64 +13,117 @@ jobs:
1313 name : " Create tag"
1414 runs-on : ubuntu-latest
1515 timeout-minutes : 10
16- if : " ${{ github.ref_type == 'branch' }}"
16+ if : " ${{ github.ref_type == 'branch' && github.run_attempt == '1' }}"
1717 concurrency :
1818 group : " ${{ github.repository_id }}-${{ github.workflow }}-tag"
19- cancel-in-progress : true
19+ cancel-in-progress : false
2020 outputs :
2121 tag-name : " ${{ steps.repo-info.outputs.version }}"
22+ tag-creation-success : " ${{ steps.tag-creation.outputs.result }}"
2223 permissions :
2324 contents : write # Needed to create a tag
2425
2526 steps :
2627 - name : " Checkout sources"
2728 uses : actions/checkout@v5
28- - name : " Parse version"
29+ with :
30+ sparse-checkout : |
31+ zip-content/module.prop
32+ sparse-checkout-cone-mode : false
33+ - name : " Parse info"
2934 id : " repo-info"
3035 shell : bash
3136 run : |
32- # Parsing version ...
37+ # Parsing info ...
3338 version="$(grep -m 1 -e '^version=' -- './zip-content/module.prop' | cut -d '=' -f '2-' -s)" || exit "${?}"
39+ now="$(date -u -Is)" || exit "${?}"
3440 printf 'version=%s\n' "${version:?}" 1>> "${GITHUB_OUTPUT?}" || exit "${?}"
35- - name : " Create tag"
41+ printf 'now=%s\n' "${now:?}" 1>> "${GITHUB_OUTPUT?}" || exit "${?}"
42+ - name : " Create annotated tag"
43+ id : tag-creation
3644 uses : actions/github-script@v7
3745 timeout-minutes : 5
3846 env :
47+ ACTOR_ID : " ${{ github.actor_id }}"
3948 TAG_NAME : " ${{ steps.repo-info.outputs.version }}"
49+ TAG_DATE : " ${{ steps.repo-info.outputs.now }}"
4050 with :
51+ result-encoding : string
4152 retries : 3
4253 script : |
4354 /* jshint esversion: 6 */
55+ function errorOut(apiName, e)
56+ {
57+ let errorMsg = apiName + '() failed';
58+ if(e)
59+ {
60+ //console.warn('e.name: ' + e.name);
61+ //console.warn('e.statusText: ' + e.statusText);
62+ if(e.response && e.response.headers) console.warn('Rate limit - remaining: ' + e.response.headers['x-ratelimit-remaining']);
63+ if(e.status || e.message) errorMsg += ' with error ' + e.status + ' (' + e.message + ')';
64+ }
65+ throw new Error(errorMsg);
66+ }
67+ const actor_id = process.env.ACTOR_ID;
4468 const tag_name = process.env.TAG_NAME;
45- console.log('::notice::Tag: ' + tag_name);
69+ const tag_date = process.env.TAG_DATE;
70+ console.log('::notice::Tag name: ' + tag_name);
71+ console.log('::notice::Tag date: ' + tag_date);
72+ const responseUser = await github.rest.users.getByUsername({
73+ username: context.actor
74+ }).catch(responseUser => responseUser);
75+ if(responseUser && responseUser.status === 200 && responseUser.data && responseUser.data.name) {
76+ // User data retrieved correctly
77+ } else {
78+ errorOut('users.getByUsername', responseUser);
79+ }
80+ // If public e-mail is missing, use default
81+ const email = responseUser.data.email ? responseUser.data.email : actor_id + '+' + context.actor + '@users.noreply.github.com';
82+ const responseTag = await github.rest.git.createTag({
83+ owner: context.repo.owner,
84+ repo: context.repo.repo,
85+ tag: tag_name,
86+ message: 'Release ' + tag_name,
87+ object: context.sha,
88+ type: 'commit',
89+ tagger: {
90+ name: responseUser.data.name,
91+ email: email,
92+ date: tag_date
93+ }
94+ }).catch(responseTag => responseTag);
95+ if(responseTag && responseTag.status === 201 && responseTag.data && responseTag.data.sha) {
96+ console.log('Tag object created correctly: ' + responseTag.data.sha);
97+ if(responseTag.data.verification)
98+ {
99+ console.log('Tag - verified: ' + responseTag.data.verification.verified);
100+ console.log('Tag - reason: ' + responseTag.data.verification.reason);
101+ console.log('Tag - verification date: ' + responseTag.data.verification.verified_at);
102+ }
103+ //console.log(JSON.stringify(responseTag.data));
104+ } else {
105+ errorOut('git.createTag', responseTag);
106+ }
46107 const response = await github.rest.git.createRef({
47108 owner: context.repo.owner,
48109 repo: context.repo.repo,
49110 ref: 'refs/tags/' + tag_name,
50- sha: context .sha
111+ sha: responseTag.data .sha
51112 }).catch(response => response);
52- if(response && response.status === 201) {
53- console.log('Tag created.' );
113+ if(response && response.status === 201 && response.data.ref ) {
114+ console.log('Tag ref created correctly: ' + response.data.ref );
54115 return true;
55116 } else if(response && response.status === 422 && response.message === 'Reference already exists') {
56- //console.warn('::warning::Tag already exist!!!');
57- throw new Error('Tag already exist!!!');
117+ console.warn('::warning::Tag already exist!!!');
58118 } else {
59- let errorMsg = 'createRef failed';
60- if(response) {
61- //if(response.name) console.warn('response.name: ' + response.name);
62- //if(response.statusText) console.warn('response.statusText: ' + response.statusText);
63- if(response.response && response.response.headers && response.response.headers['x-ratelimit-remaining']) console.warn('Remaining rate limit: ' + response.response.headers['x-ratelimit-remaining']);
64- if(response.status && response.message) errorMsg += ' with error ' + response.status + ' (' + response.message + ')';
65- }
66- throw new Error(errorMsg);
119+ errorOut('git.createRef', response);
67120 }
68121 return false;
69122
70123 call-workflow :
71124 name : " Call workflow"
72125 needs : [create-tag]
73- if : " ${{ github.ref_type == 'branch ' }}"
126+ if : " ${{ needs.create-tag.outputs.tag-creation-success == 'true ' }}"
74127 uses : " ./.github/workflows/auto-release-from-tag.yml"
75128 with :
76129 tag-name : " ${{ needs.create-tag.outputs.tag-name }}"
0 commit comments