Skip to content

Commit 0f9bb22

Browse files
Merge pull request #425 from CheckmarxDev/nightly-releases
Create development release for JS Wrapper
2 parents e9b0cab + 0837b82 commit 0f9bb22

File tree

4 files changed

+163
-43
lines changed

4 files changed

+163
-43
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Delete packages and releases
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag:
7+
description: 'Tag to delete'
8+
required: true
9+
type: string
10+
workflow_dispatch:
11+
inputs:
12+
tag:
13+
description: 'Tag to delete'
14+
required: true
15+
16+
permissions:
17+
id-token: write
18+
contents: write
19+
packages: write
20+
21+
22+
jobs:
23+
delete:
24+
runs-on: ubuntu-latest
25+
steps:
26+
27+
- name: Delete npm packages
28+
continue-on-error: true
29+
run: |
30+
31+
echo "Deleting all npm packages whose name ends with '-${{inputs.tag}}.0'"
32+
33+
VERSION_IDS=($(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/CheckmarxDev/packages/npm/ast-cli-javascript-wrapper/versions | jq '.[]|select(.name | contains("-${{inputs.tag}}.0"))|.id'))
34+
35+
for versionId in "${VERSION_IDS[@]}"
36+
do
37+
echo "Deleting version $versionId..."
38+
curl -L -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/orgs/CheckmarxDev/packages/npm/ast-cli-javascript-wrapper/versions/$versionId"
39+
echo "Version $versionId deleted successfully!"
40+
done
41+
42+
- name: Delete releases and tags
43+
continue-on-error: true
44+
uses: dev-drprasad/delete-older-releases@v0.2.1
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
47+
with:
48+
keep_latest: 0
49+
delete_tag_pattern: "-${{inputs.tag}}.0"
50+
delete_tags: true

.github/workflows/manual-tag.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/nightly.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Nightly Release
2+
3+
permissions:
4+
id-token: write
5+
contents: write
6+
packages: write
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
13+
jobs:
14+
nightly:
15+
uses: CheckmarxDev/ast-cli-javascript-wrapper/.github/workflows/release.yml@main
16+
secrets: inherit

.github/workflows/release.yml

Lines changed: 97 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,119 @@
1-
name: Node.js Package
1+
name: Javascript Wrapper Release
22

33
on:
4-
push:
5-
tags:
6-
- "*"
4+
workflow_call:
5+
inputs:
6+
cliTag:
7+
description: 'CLI tag name'
8+
required: false
9+
type: string
10+
default: 2.0.0-nightly
11+
jsTag:
12+
description: 'JS Wrapper tag name'
13+
required: false
14+
type: string
15+
default: nightly
16+
dev:
17+
description: 'Is dev build'
18+
required: false
19+
default: true
20+
type: boolean
21+
workflow_dispatch:
22+
inputs:
23+
cliTag:
24+
description: 'CLI tag name (ignored if not dev build)'
25+
required: false
26+
jsTag:
27+
description: 'Tag name (ignored if not dev build)'
28+
required: false
29+
type: string
30+
default: rc
31+
dev:
32+
description: 'Is dev build'
33+
required: false
34+
default: true
35+
type: boolean
36+
37+
permissions:
38+
id-token: write
39+
contents: write
40+
packages: write
741

842
jobs:
43+
delete:
44+
uses: CheckmarxDev/ast-cli-javascript-wrapper/.github/workflows/delete-packages-and-releases.yml@main
45+
with:
46+
tag: ${{ inputs.jsTag }}
47+
secrets: inherit
48+
if: inputs.dev == true
949
release:
1050
runs-on: ubuntu-latest
1151
steps:
52+
53+
# CHECKOUT PROJECT
1254
- uses: actions/checkout@v3
1355
with:
1456
fetch-depth: 0
15-
- name: Set env
16-
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
57+
58+
# GIT CONFIGURATION
59+
- run: |
60+
git config user.name github-actions
61+
git config user.email github-actions@github.com
62+
63+
# SETUP NODE
1764
- uses: actions/setup-node@v3.6.0
1865
with:
1966
node-version: 10
2067
registry-url: https://npm.pkg.github.com/
21-
- run: npm ci
22-
- name: npm build
23-
run: npm run build
24-
- name: Set up NPM authentication
25-
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc
26-
- run: npm publish --access public
27-
env:
28-
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
29-
- name: Changelog
30-
uses: Bullrich/generate-release-changelog@master
31-
id: Changelog
68+
69+
# GET TAG NAME
70+
- name: Generate Tag name
71+
run: |
72+
if [ ${{ inputs.dev }} == true ]; then
73+
echo "TAG_NAME=$(npm version prerelease --preid=${{ inputs.jsTag }} --no-git-tag-version --allow-same-version)" >> $GITHUB_ENV
74+
else
75+
echo "TAG_NAME=$(npm version patch)" >> $GITHUB_ENV
76+
fi
77+
78+
# DOWNLOAD CLI IF IT IS A DEV VERSION AND A CLI TAG WAS PROVIDED
79+
- name: Download cli with tag ${{ inputs.cliTag }}
80+
if: inputs.dev == true && inputs.cliTag != ''
81+
run: |
82+
# Update binaries
83+
chmod +x ./.github/scripts/update_cli.sh
84+
./.github/scripts/update_cli.sh ${{ inputs.cliTag }}
85+
86+
# RUN NPM INSTALL AND BUILD
87+
- name: NPM ci and build
88+
run: |
89+
npm ci
90+
npm run build
91+
92+
# PUSH TAGS IF IT IS A RELEASE
93+
- name: Push tag if release
94+
if: inputs.dev == false
95+
run: git push && git push --tags
96+
97+
# PUBLISH NPM PACKAGE
98+
- name: Publish npm package
99+
run: |
100+
if [ ${{ inputs.dev }} == true ]; then
101+
npm publish --tag=${{ inputs.jsTag }}
102+
else
103+
npm publish --access public
104+
fi
32105
env:
33-
REPO: ${{ github.repository }}
106+
NODE_AUTH_TOKEN: ${{secrets.PERSONAL_ACCESS_TOKEN}}
107+
108+
# CREATE RELEASE
34109
- name: Create Release
35110
id: create_release
36111
uses: actions/create-release@v1
37112
env:
38113
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39114
with:
40-
tag_name: ${{ github.ref }}
41-
release_name: Release ${{ github.ref }}
42-
body: |
43-
${{ steps.Changelog.outputs.changelog }}
115+
tag_name: ${{env.TAG_NAME}}
116+
release_name: Release ${{env.TAG_NAME}}
117+
body: ${{ steps.Changelog.outputs.changelog }}
44118
draft: false
45-
prerelease: false
119+
prerelease: ${{ inputs.dev }}

0 commit comments

Comments
 (0)