File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // @ts -check
2+
3+ /** @param {import('@actions/github-script').AsyncFunctionArguments } args */
4+ module . exports = async ( { github, context } ) => {
5+ const tag = context . payload . release ?. tag_name ;
6+ if ( ! tag ) {
7+ throw new Error ( "No release tag found in event payload" ) ;
8+ }
9+
10+ const match = tag . match ( / ^ ( v \d + ) \. \d + \. \d + / ) ;
11+ if ( ! match ) {
12+ throw new Error ( `Tag "${ tag } " does not match semver pattern vX.Y.Z` ) ;
13+ }
14+
15+ const majorTag = match [ 1 ] ;
16+ const sha = context . sha ;
17+
18+ const tagsToUpdate = [ majorTag , "latest" ] ;
19+
20+ for ( const tagName of tagsToUpdate ) {
21+ const ref = `tags/${ tagName } ` ;
22+ try {
23+ await github . rest . git . updateRef ( {
24+ owner : context . repo . owner ,
25+ repo : context . repo . repo ,
26+ ref,
27+ sha,
28+ force : true ,
29+ } ) ;
30+ console . log ( `Updated ${ ref } to ${ sha } ` ) ;
31+ } catch ( error ) {
32+ if ( error . status === 422 ) {
33+ await github . rest . git . createRef ( {
34+ owner : context . repo . owner ,
35+ repo : context . repo . repo ,
36+ ref : `refs/${ ref } ` ,
37+ sha,
38+ } ) ;
39+ console . log ( `Created ${ ref } at ${ sha } ` ) ;
40+ } else {
41+ throw error ;
42+ }
43+ }
44+ }
45+ } ;
Original file line number Diff line number Diff line change 1111 actions-tagger :
1212 runs-on : ubuntu-latest
1313 steps :
14- - uses : Actions-R-Us/actions-tagger@148653c6179832f8392d083de6b46ad3dcc54de3
14+ - uses : actions/checkout@v4
15+ - uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
1516 with :
16- publish_latest_tag : true
17- token : ${{ secrets.GITHUB_TOKEN }}
17+ script : |
18+ const fn = require('./.github/scripts/update-major-tag.js');
19+ await fn({ github, context });
You can’t perform that action at this time.
0 commit comments