Skip to content
This repository was archived by the owner on Dec 19, 2022. It is now read-only.

Commit d81b782

Browse files
committed
build: add release.yml workflow
1 parent 0ad746d commit d81b782

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

.github/workflows/release.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "**"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [14.x]
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Setup Node.js environment ${{ matrix.node-version }}
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
22+
- name: Setup PNPM
23+
uses: pnpm/action-setup@v2
24+
with:
25+
version: 6.x.x
26+
run_install: true
27+
28+
- name: ESLint check
29+
run: pnpm lint
30+
31+
- name: Build
32+
run: pnpm build
33+
34+
publish-docker:
35+
needs: [build]
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v2
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v1
42+
43+
- name: Login to Docker
44+
uses: docker/login-action@v1
45+
with:
46+
registry: ${{ secrets.DOCKER_REGISTRY }}
47+
username: ${{ secrets.DOCKER_USERNAME }}
48+
password: ${{ secrets.DOCKER_PASSWORD }}
49+
50+
- name: Extract tag name
51+
shell: bash
52+
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
53+
id: extract_tag
54+
55+
- name: Build and push image
56+
uses: docker/build-push-action@v2
57+
with:
58+
context: .
59+
file: ./Dockerfile
60+
push: true
61+
platforms: linux/amd64
62+
tags: ${{ secrets.DOCKER_REGISTRY }}/picacomic-crawler:${{ steps.extract_tag.outputs.tag }}
63+
64+
release:
65+
needs: [build, publish-docker]
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Checkout
69+
uses: actions/checkout@v2
70+
with:
71+
# Fetch all history
72+
fetch-depth: 0
73+
74+
- name: Generate Changelog
75+
id: changelog
76+
shell: bash
77+
env:
78+
CURRENT: ${{ github.ref }}
79+
# Special thanks to this post on Stack Overflow regarding change set between two tags:
80+
# https://stackoverflow.com/questions/12082981
81+
# Do note that actions/checkout will enter detach mode by default, so you won't have
82+
# access to HEAD ref. Use GitHub-Action-supplied `github.ref` instead.
83+
# Special thanks to this issue ticket regarding escaping newline:
84+
# https://github.com/actions/create-release/issues/25
85+
# We use Bash parameter expansion to do find-and-replace.
86+
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
87+
# Also we cannot use git rev-list because it always prepend "commit <hash>"
88+
# See https://stackoverflow.com/questions/36927089/
89+
run: |
90+
current_tag=${CURRENT/refs\/tags\//}
91+
last_tag=`git describe --tags --abbrev=0 "$current_tag"^ 2>/dev/null || echo`
92+
if [ $last_tag ]; then
93+
changelog=`git log --pretty="format:%H: %s" ${last_tag}..$current_tag`
94+
else
95+
changelog=`git log --pretty="format:%H: %s"`
96+
fi
97+
changelog="${changelog//'%'/'%25'}"
98+
changelog="${changelog//$'\n'/' %0A'}"
99+
echo "::set-output name=value::Change set since ${last_tag:-the beginning}: %0A%0A$changelog"
100+
- name: GitHub Release
101+
uses: actions/create-release@v1
102+
env:
103+
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB_PUBLISH }}
104+
with:
105+
tag_name: ${{ github.ref }}
106+
release_name: ${{ github.ref }}
107+
draft: false
108+
prerelease: false
109+
body: |
110+
${{ steps.changelog.outputs.value }}

0 commit comments

Comments
 (0)