-
Notifications
You must be signed in to change notification settings - Fork 1
139 lines (133 loc) · 6.2 KB
/
manually_release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Manually Release Workflow
on:
workflow_dispatch:
inputs:
prerelease:
description: 'Is this a pre-release?'
required: true
default: false
type: boolean
useRetrievedVersion:
description: 'Use the version retrieved from the project?'
required: true
default: true
type: boolean
alternativeVersion:
description: 'Alternative version to use if not using the retrieved version'
required: false
type: string
namespace:
description: 'Namespace to use for the image, default to the repository owner'
required: false
type: string
permissions: write-all
jobs:
build:
runs-on:
ubuntu-latest
timeout-minutes: 360 # 6 hours
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
build-scan-publish: false
- name: Retrieve Version
run: |
chmod +x gradlew
VERSION_NAME=$(./gradlew -q :version)
echo "VERSION_NAME=$VERSION_NAME" >> "$GITHUB_OUTPUT"
id: project_version
- name: Get version
run: |
echo "raw_version_name=${{ steps.project_version.outputs.VERSION_NAME }}" >> $GITHUB_ENV
if ${{ github.event.inputs.useRetrievedVersion }}; then
echo "version_name=v${{ steps.project_version.outputs.VERSION_NAME }}" >> $GITHUB_ENV
else
echo "version_name=${{ github.event.inputs.alternativeVersion }}" >> $GITHUB_ENV
fi
- name: Set Namespace
shell: bash
run: |
if [[ -z "${{ github.event.inputs.namespace }}" ]]; then
echo "namespace=${{ github.repository_owner }}" >> $GITHUB_ENV
else
echo "namespace=${{ github.event.inputs.namespace }}" >> $GITHUB_ENV
fi
- name: Install Dependencies
# TODO: retrieve version from gradle task
run: |
git clone https://github.com/roll-w/web-common-starter
cd web-common-starter
git checkout v0.2.1
mvn -f web-common-parent/ clean install
cd ..
- name: Create Tag
uses: actions/github-script@v7.0.1
id: create_tag
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ env.version_name }}',
sha: context.sha
})
- name: Checkout Tag
uses: actions/checkout@v4
with:
ref:
${{ env.version_name }}
- name: Build Package and Docker Image
id: build
continue-on-error: true
run: |
chmod +x gradlew
./gradlew packageImage
- name: Push Image
id: push
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker tag lampray:${{ env.raw_version_name }} ghcr.io/${{ env.namespace }}/lampray:${{ env.raw_version_name }}
docker push ghcr.io/${{ env.namespace }}/lampray:${{ env.raw_version_name }}
if ! ${{ github.event.inputs.prerelease }}; then
docker tag ghcr.io/${{ env.namespace }}/lampray:${{ env.raw_version_name }} ghcr.io/${{ env.namespace }}/lampray:latest
docker push ghcr.io/${{ env.namespace }}/lampray:latest
fi
sha=$(docker inspect ghcr.io/${{ env.namespace }}/lampray:${{ env.raw_version_name }} --format='{{index .RepoDigests 0}}')
echo "digest=$sha" >> $GITHUB_OUTPUT
- name: Release
if: steps.build.outcome == 'success'
uses: softprops/action-gh-release@v2
with:
body: |
# ${{ env.version_name }}
Release for version ${{ env.raw_version_name }}
## Changes
## Artifacts
- Image: ghcr.io/${{ env.namespace }}/lampray:${{ env.raw_version_name }}
- sha: `${{ steps.push.outputs.digest }}`
Pull image from `ghcr.io/${{ env.namespace }}/lampray:${{ env.raw_version_name }}`
or download the image package from current release assets.
draft: true
tag_name: ${{ env.version_name }}
prerelease: ${{ github.event.inputs.prerelease }}
files: |
build/dist/lampray-${{ env.raw_version_name }}-dist.tar.gz
build/dist/lampray-${{ env.raw_version_name }}-image.tar.gz
- name: Remove Tag
uses: actions/github-script@v7.0.1
if: failure() && steps.build.outcome == 'failure'
with:
script: |
github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ env.version_name }}'
})