|
3 | 3 | name: Release |
4 | 4 |
|
5 | 5 | on: |
6 | | - workflow_call: |
7 | | - inputs: |
8 | | - version_type: |
9 | | - description: 'Type of version bump' |
10 | | - required: true |
11 | | - type: string |
12 | | - |
13 | 6 | workflow_dispatch: |
14 | 7 | inputs: |
15 | 8 | version_type: |
|
22 | 15 | - minor |
23 | 16 | - major |
24 | 17 |
|
25 | | -permissions: |
26 | | - contents: write |
27 | | - id-token: write |
28 | | - |
29 | 18 | jobs: |
30 | | - release: |
31 | | - runs-on: ubuntu-latest |
32 | | - environment: staging |
33 | | - name: Release the project |
34 | | - steps: |
35 | | - - name: Checkout sources |
36 | | - uses: actions/checkout@v4 |
37 | | - with: |
38 | | - fetch-depth: 0 |
39 | | - |
40 | | - - name: Install node 20 |
41 | | - uses: actions/setup-node@v4 |
42 | | - with: |
43 | | - node-version: 20 |
44 | | - cache: npm |
45 | | - registry-url: 'https://registry.npmjs.org' |
46 | | - |
47 | | - - name: Update npm |
48 | | - run: npm install -g npm@11.5.1 |
49 | | - |
50 | | - - name: Configure git |
51 | | - run: | |
52 | | - git config user.name "${{ github.actor }}" |
53 | | - git config user.email "${{ github.actor }}@users.noreply.github.com" |
54 | | -
|
55 | | - - name: get previous released annotated tag |
56 | | - id: last-release |
57 | | - run: | |
58 | | - echo "base-tag=$(git describe | awk -F '-' '{print $1}')" >> "$GITHUB_OUTPUT" |
59 | | - echo "full-tag=$(git describe)" >> "$GITHUB_OUTPUT" |
60 | | -
|
61 | | - - name: get first tag in current development iteration according to base |
62 | | - id: fetch-tag |
63 | | - if: ${{ contains(steps.last-release.outputs.full-tag , '-ea.') }} |
64 | | - run: | |
65 | | - echo "oldest-tag=$(git for-each-ref --sort=creatordate --format '%(refname:lstrip=2)' refs/tags | grep ${{ steps.last-release.outputs.base-tag }} | head -n 1)" >> "$GITHUB_OUTPUT" |
66 | | -
|
67 | | - - name: determine semver component to bump |
68 | | - id: bump-decision |
69 | | - run: | |
70 | | - echo "bump-part=${{ inputs.version_type }}" >> "$GITHUB_OUTPUT" |
71 | | -
|
72 | | - - name: Update package with new version |
73 | | - id: bump |
74 | | - run: | |
75 | | - if [[ "${{ inputs.version_type }}" == "prerelease" ]]; then |
76 | | - echo "version=$(npm version prerelease --no-git-tag-version --preid ea)" >> "$GITHUB_OUTPUT" |
77 | | - else |
78 | | - echo "version=$(npm version ${{ steps.bump-decision.outputs.bump-part }} --no-git-tag-version )" >> "$GITHUB_OUTPUT" |
79 | | - fi |
80 | | -
|
81 | | - - name: Install project modules |
82 | | - run: npm ci |
83 | | - |
84 | | - - name: Compile project |
85 | | - run: npm run compile |
86 | | - |
87 | | - - name: Publish package |
88 | | - run: npm publish --access public --provenance ${{ inputs.version_type == 'prerelease' && '--tag prerelease' || '' }} |
89 | | - |
90 | | - - name: Commit and push package modifications |
91 | | - run: | |
92 | | - git add package.json |
93 | | - git add package-lock.json |
94 | | - git commit -m "build: updated package with ${{ steps.bump.outputs.version }} [skip ci]" |
95 | | - git push |
96 | | -
|
97 | | - - name: Create and push new tag |
98 | | - run: | |
99 | | - git tag ${{ steps.bump.outputs.version }} -m "${{ steps.bump.outputs.version }}" |
100 | | - git push origin ${{ steps.bump.outputs.version }} |
101 | | -
|
102 | | - - name: Create release notes for ${{ steps.bump.outputs.version }} release |
103 | | - if: inputs.version_type != 'prerelease' |
104 | | - uses: actions/github-script@v6 |
105 | | - id: release-notes |
106 | | - with: |
107 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
108 | | - script: | |
109 | | - const repo_name = context.payload.repository.full_name |
110 | | - const response = await github.request('POST /repos/' + repo_name + '/releases/generate-notes', { |
111 | | - tag_name: '${{ steps.bump.outputs.version }}', |
112 | | - previous_tag_name: '${{ steps.fetch-tag.outputs.oldest-tag != '' && steps.fetch-tag.outputs.oldest-tag || steps.last-release.outputs.base-tag }}' |
113 | | - }) |
114 | | - return response.data.body |
115 | | -
|
116 | | - - name: Create a release |
117 | | - uses: actions/github-script@v6.4.1 |
118 | | - with: |
119 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
120 | | - script: | |
121 | | - const repo_name = context.payload.repository.full_name |
122 | | - const isPrerelease = '${{ inputs.version_type }}' === 'prerelease'; |
123 | | - const releaseConfig = { |
124 | | - tag_name: '${{ steps.bump.outputs.version }}', |
125 | | - name: '${{ steps.bump.outputs.version }}', |
126 | | - prerelease: isPrerelease |
127 | | - }; |
128 | | -
|
129 | | - if (isPrerelease) { |
130 | | - releaseConfig.generate_release_notes = true; |
131 | | - } else { |
132 | | - releaseConfig.draft = false; |
133 | | - releaseConfig.body = ${{ steps.release-notes.outputs.result }}; |
134 | | - releaseConfig.make_latest = 'true'; |
135 | | - } |
136 | | -
|
137 | | - const response = await github.request('POST /repos/' + repo_name + '/releases', releaseConfig); |
| 19 | + publish-release: |
| 20 | + uses: ./.github/workflows/publish-switch.yml |
| 21 | + with: |
| 22 | + ref: ${{ github.ref }} |
| 23 | + is_prerelease: false |
| 24 | + version_type: ${{ inputs.version_type }} |
0 commit comments