Skip to content

Commit 0142e01

Browse files
authored
ci: create Release workflow for js-api (#79)
* ci: create new release workflow * ci: add to release workflow bumping part logic Related Jira issue: https://issues.redhat.com/browse/APPENG-2061 --------- Signed-off-by: Zvi Grinberg <[email protected]>
1 parent 60752b1 commit 0142e01

File tree

2 files changed

+153
-3
lines changed

2 files changed

+153
-3
lines changed

.github/workflows/release.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
name: Stage
3+
4+
env:
5+
# 🖊️ EDIT to change the image build settings.
6+
IMAGE_NAME: exhort-javascript-api
7+
IMAGE_REGISTRY: quay.io/ecosystem-appeng
8+
DOCKERFILE_PATH: ./docker-image/Dockerfiles/Dockerfile.alpha
9+
10+
on:
11+
workflow_dispatch:
12+
pull_request:
13+
types:
14+
- closed
15+
branches:
16+
- 'main'
17+
paths:
18+
- "generated/**"
19+
- "src/**"
20+
- "package-lock.json"
21+
- "package.json"
22+
- "tsconfig.json"
23+
24+
jobs:
25+
release:
26+
runs-on: ubuntu-latest
27+
environment: staging
28+
if: github.repository_owner == 'RHEcosystemAppEng' && startsWith(github.head_ref, 'release/')
29+
name: Release the project
30+
steps:
31+
- name: Checkout sources
32+
uses: actions/checkout@v3
33+
with:
34+
ssh-key: ${{ secrets.DEPLOY_KEY }}
35+
36+
- name: Install node 18
37+
uses: actions/setup-node@v3
38+
with:
39+
node-version: 18
40+
cache: npm
41+
registry-url: 'https://npm.pkg.github.com'
42+
43+
- name: Configure git
44+
run: |
45+
git config user.name "${{ github.actor }}"
46+
git config user.email "${{ github.actor }}@users.noreply.github.com"
47+
48+
- name: get previous released annotated tag
49+
id: last-release
50+
run: |
51+
echo "base-tag=$(git describe | awk -F '-' '{print $1}')" >> "$GITHUB_OUTPUT"
52+
echo "full-tag=$(git describe)" >> "$GITHUB_OUTPUT"
53+
54+
55+
- name: get first tag in current development iteration according to base
56+
id: fetch-tag
57+
if: ${{ contains(steps.last-release.outputs.full-tag , 'ea')
58+
run: |
59+
echo "oldest-tag=$(git for-each-ref --sort=creatordate --format '%(refname:lstrip=2)' refs/tags | grep ${{ steps.last-release.outputs.base-tag }} )" >> "$GITHUB_OUTPUT"
60+
61+
- name: determine semver component to bump
62+
env:
63+
BUMP_PART: ${{ contains(github.event.pull_request.title,'major') && 'major' || 'check-minor' }}
64+
id: bump-decision
65+
run: |
66+
echo "bump-part=$(${{ env.BUMP_PART == 'check-minor' && '${{ contains(github.event.pull_request.title,'minor') && 'minor' || 'patch' }}' || 'major' }})" >> "$GITHUB_OUTPUT"
67+
68+
69+
- name: Update package with new version
70+
id: bump
71+
run: |
72+
echo "version=$(npm version ${{ steps.bump-decision.outputs.bump-part }} --no-git-tag-version )" >> "$GITHUB_OUTPUT"
73+
74+
- name: Install project modules
75+
run: npm ci
76+
77+
- name: Compile project
78+
run: npm run compile
79+
80+
- name: Publish package
81+
env:
82+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
run: npm publish
84+
85+
- name: Commit and push package modifications
86+
run: |
87+
git add package.json
88+
git add package-lock.json
89+
git commit -m "build: updated package with ${{ steps.bump.outputs.version }} [skip ci]"
90+
git push
91+
92+
- name: Create and push new tag
93+
run: |
94+
git tag ${{ steps.bump.outputs.version }} -m "${{ steps.bump.outputs.version }}"
95+
git push origin ${{ steps.bump.outputs.version }}
96+
97+
- name: Create release notes for ${{ steps.bump.outputs.version }} release
98+
uses: actions/github-script@v6
99+
id: release-notes
100+
with:
101+
github-token: ${{ secrets.STAGING_PAT }}
102+
script: |
103+
const repo_name = context.payload.repository.full_name
104+
const response = await github.request('POST /repos/' + repo_name + '/releases' + '/generate-notes', {
105+
tag_name: '${{ steps.bump.outputs.version }}',
106+
previous_tag_name: '${{ steps.fetch-tag.outputs.oldest-tag != '' && steps.fetch-tag.outputs.oldest-tag || steps.last-release.outputs.base-tag }}'
107+
})
108+
return response.data.body
109+
110+
111+
112+
- name: Create a release
113+
uses: actions/[email protected]
114+
with:
115+
github-token: ${{ secrets.STAGING_PAT }}
116+
script: |
117+
const repo_name = context.payload.repository.full_name
118+
const response = await github.request('POST /repos/' + repo_name + '/releases', {
119+
tag_name: '${{ steps.bump.outputs.version }}',
120+
name: '${{ steps.bump.outputs.version }}',
121+
draft: false,
122+
body: ${{ steps.release-notes.outputs.result }},
123+
prerelease: false,
124+
make_latest: 'true'
125+
})
126+
127+
- name: Build Image With buildah
128+
id: build-image
129+
uses: redhat-actions/buildah-build@v2
130+
with:
131+
image: ${{ env.IMAGE_NAME }}
132+
tags: ${{ steps.bump.outputs.version }}
133+
dockerfiles: |
134+
${{ env.DOCKERFILE_PATH }}
135+
build-args: |
136+
PACKAGE_REGISTRY_ACCESS_TOKEN=${{ secrets.PACKAGE_REGISTRY_ACCESS_TOKEN }}
137+
context: docker-image
138+
139+
- name: Push Image To Registry
140+
uses: redhat-actions/push-to-registry@v2
141+
with:
142+
image: ${{ steps.build-image.outputs.image }}
143+
tags: ${{ steps.build-image.outputs.tags }}
144+
registry: ${{ env.IMAGE_REGISTRY }}
145+
username: ${{ secrets.IMAGE_REGISTRY_USER }}
146+
password: ${{ secrets.IMAGE_REGISTRY_PASSWORD }}

.github/workflows/stage.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ env:
99

1010
on:
1111
workflow_dispatch:
12-
push:
12+
pull_request:
13+
types:
14+
- closed
1315
branches:
14-
- main
16+
- 'main'
17+
1518
paths:
1619
- "generated/**"
1720
- "src/**"
@@ -23,7 +26,8 @@ on:
2326
jobs:
2427
stage:
2528
runs-on: ubuntu-latest
26-
if: github.repository_owner == 'RHEcosystemAppEng'
29+
# Branches that starts with `release/` shouldn't trigger this workflow, as these are triggering the release workflow.
30+
if: github.repository_owner == 'RHEcosystemAppEng' && !startsWith(github.head_ref, 'release/')
2731
environment: staging
2832
name: Stage the project
2933
steps:

0 commit comments

Comments
 (0)