Skip to content

Commit 9b6b87e

Browse files
author
Archit Aggarwal
authored
Add GitHub Action workflow for release automation (#73)
**Add a GitHub Action job to trigger a release process** which includes operations of: 1. Creating and pushing the release tag to the repository 2. Verifying the pushed tag (performing a diff with the commit ID which is tagged) 3. Creating a ZIP for the release asset. 4. Verifying the ZIP by performing a diff check and running unit tests on the unzipped files. 5. Creating a release on the repository for the tag, and uploading the ZIP as the release asset The workflow can be manually triggered and takes the input values of **Commit ID** (to create a release for) and the **Version string** for tagging the release with
1 parent c3ed2a2 commit 9b6b87e

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

.github/workflows/release.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Release automation
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
commit_id:
7+
description: 'Commit ID to tag and create a release for'
8+
required: true
9+
version_number:
10+
description: 'Release Version Number (Eg, v1.0.0)'
11+
required: true
12+
13+
jobs:
14+
tag-commit:
15+
name: Tag commit
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
with:
21+
ref: ${{ github.event.inputs.commit_id }}
22+
- name: Configure git identity
23+
run: |
24+
git config --global user.name "Release Workflow"
25+
- name: Tag Commit and Push to remote
26+
run: |
27+
git tag ${{ github.event.inputs.version_number }} -a -m "coreJSON Library ${{ github.event.inputs.version_number }}"
28+
git push origin --tags
29+
- name: Verify tag on remote
30+
run: |
31+
git tag -d ${{ github.event.inputs.version_number }}
32+
git remote update
33+
git checkout tags/${{ github.event.inputs.version_number }}
34+
git diff ${{ github.event.inputs.commit_id }} tags/${{ github.event.inputs.version_number }}
35+
create-zip:
36+
needs: tag-commit
37+
name: Create ZIP and verify package for release asset.
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Install ZIP tools
41+
run: sudo apt-get install zip unzip
42+
- name: Checkout code
43+
uses: actions/checkout@v2
44+
with:
45+
ref: ${{ github.event.inputs.commit_id }}
46+
path: coreJSON
47+
submodules: recursive
48+
- name: Checkout disabled submodules
49+
run: |
50+
cd coreJSON
51+
git submodule update --init --checkout --recursive
52+
- name: Create ZIP
53+
run: |
54+
zip -r coreJSON-${{ github.event.inputs.version_number }}.zip coreJSON -x "*.git*"
55+
ls ./
56+
- name: Validate created ZIP
57+
run: |
58+
mkdir zip-check
59+
mv coreJSON-${{ github.event.inputs.version_number }}.zip zip-check
60+
cd zip-check
61+
unzip coreJSON-${{ github.event.inputs.version_number }}.zip -d coreJSON-${{ github.event.inputs.version_number }}
62+
ls coreJSON-${{ github.event.inputs.version_number }}
63+
diff -r -x "*.git*" coreJSON-${{ github.event.inputs.version_number }}/coreJSON/ ../coreJSON/
64+
cd ../
65+
- name: Build
66+
run: |
67+
cd zip-check/coreJSON-${{ github.event.inputs.version_number }}/coreJSON
68+
sudo apt-get install -y lcov
69+
cmake -S test -B build/ \
70+
-G "Unix Makefiles" \
71+
-DCMAKE_BUILD_TYPE=Debug \
72+
-DBUILD_CLONE_SUBMODULES=ON \
73+
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror'
74+
make -C build/ all
75+
- name: Test
76+
run: |
77+
cd zip-check/coreJSON-${{ github.event.inputs.version_number }}/coreJSON/build/
78+
ctest -E system --output-on-failure
79+
cd ..
80+
- name: Create artifact of ZIP
81+
uses: actions/upload-artifact@v2
82+
with:
83+
name: coreJSON-${{ github.event.inputs.version_number }}.zip
84+
path: zip-check/coreJSON-${{ github.event.inputs.version_number }}.zip
85+
create-release:
86+
needs: create-zip
87+
name: Create Release and Upload Release Asset
88+
runs-on: ubuntu-latest
89+
steps:
90+
- name: Create Release
91+
id: create_release
92+
uses: actions/create-release@v1
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
with:
96+
tag_name: ${{ github.event.inputs.version_number }}
97+
release_name: ${{ github.event.inputs.version_number }}
98+
body: Release ${{ github.event.inputs.version_number }} of the coreJSON Library.
99+
draft: false
100+
prerelease: false
101+
- name: Download ZIP artifact
102+
uses: actions/download-artifact@v2
103+
with:
104+
name: coreJSON-${{ github.event.inputs.version_number }}.zip
105+
- name: Upload Release Asset
106+
id: upload-release-asset
107+
uses: actions/upload-release-asset@v1
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
with:
111+
upload_url: ${{ steps.create_release.outputs.upload_url }}
112+
asset_path: ./coreJSON-${{ github.event.inputs.version_number }}.zip
113+
asset_name: coreJSON-${{ github.event.inputs.version_number }}.zip
114+
asset_content_type: application/zip

0 commit comments

Comments
 (0)