Skip to content

Commit b7935ac

Browse files
authored
Merge pull request #102 from junkurihara/fix/release-actions
fix: fix release flow
2 parents 9340679 + cf1f7a3 commit b7935ac

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

.github/workflows/docker_build_push.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on:
44
branches:
55
- "develop"
66
- "main"
7-
tags:
8-
- "*.*.*"
7+
pull_request:
8+
types: [synchronize, opened]
99

1010
env:
1111
GHCR: ghcr.io
@@ -119,19 +119,19 @@ jobs:
119119
username: ${{ github.actor }}
120120
password: ${{ secrets.GITHUB_TOKEN }}
121121

122-
# - name: Nightly build test on amd64 for pull requests
123-
# if: ${{ github.event_name == 'pull_request' }}
124-
# uses: docker/build-push-action@v5
125-
# with:
126-
# context: .
127-
# build-args: ${{ matrix.build-args }}
128-
# push: false
129-
# build-contexts: ${{ matrix.build-contexts }}
130-
# file: ${{ matrix.dockerfile }}
131-
# cache-from: type=gha,scope=rpxy-nightly-${{ matrix.target }}
132-
# cache-to: type=gha,mode=max,scope=rpxy-nightly-${{ matrix.target }}
133-
# platforms: linux/amd64
134-
# labels: ${{ steps.meta.outputs.labels }}
122+
- name: Nightly build test on amd64 for pull requests
123+
if: ${{ github.event_name == 'pull_request' }}
124+
uses: docker/build-push-action@v5
125+
with:
126+
context: .
127+
build-args: ${{ matrix.build-args }}
128+
push: false
129+
build-contexts: ${{ matrix.build-contexts }}
130+
file: ${{ matrix.dockerfile }}
131+
cache-from: type=gha,scope=rpxy-nightly-${{ matrix.target }}
132+
cache-to: type=gha,mode=max,scope=rpxy-nightly-${{ matrix.target }}
133+
platforms: linux/amd64
134+
labels: ${{ steps.meta.outputs.labels }}
135135

136136
- name: Nightly build and push from develop branch
137137
if: ${{ (github.ref_name == 'develop') && (github.event_name == 'push') }}

.github/workflows/release.yml

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ on:
55
- "Build and publish docker"
66
types:
77
- "completed"
8+
branches:
9+
- main
10+
- develop
11+
pull_request:
12+
types: [closed]
13+
branches:
14+
- main
815

916
jobs:
1017
on-success:
1118
runs-on: ubuntu-latest
12-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
19+
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'pull_request' }}
1320
strategy:
1421
fail-fast: false
1522
matrix:
@@ -70,59 +77,72 @@ jobs:
7077

7178
steps:
7279
- run: "echo 'The relese triggering workflows passed'"
80+
7381
- name: "set env"
82+
id: "set-env"
7483
run: |
75-
if [ ${{ matrix.platform }} = "linux/amd64" ];then PLATFORM_MAP="x86_64";else PLATFORM_MAP="aarch64";fi
76-
if [ ${{ github.ref_name == 'develop' }} ];then BUILD_NAME="rpxy-nightly";else BUILD_NAME="rpxy";fi
77-
echo "PLATFORM_MAP=${PLATFORM_MAP}" >> $GITHUB_ENV
78-
echo "TARGET_NAME=${BUILD_NAME}-${PLATFORM_MAP}-unknown-linux-${{ matrix.target }}${{ matrix.build-feature }}" >> $GITHUB_ENV
84+
if [ ${{ matrix.platform }} == 'linux/amd64' ]; then PLATFORM_MAP="x86_64"; else PLATFORM_MAP="aarch64"; fi
85+
if [ ${{ github.ref_name }} == 'develop' ]; then BUILD_NAME="-nightly"; else BUILD_NAME=""; fi
86+
if [ ${{ github.ref_name }} == 'develop' ]; then BUILD_IMG="nightly"; else BUILD_IMG="latest"; fi
87+
echo "build_img=${BUILD_IMG}" >> $GITHUB_OUTPUT
88+
echo "target_name=rpxy${BUILD_NAME}-${PLATFORM_MAP}-unknown-linux-${{ matrix.target }}${{ matrix.build-feature }}" >> $GITHUB_OUTPUT
7989
8090
- name: "docker pull and extract binary from docker image"
8191
id: "extract-binary"
8292
run: |
83-
CONTAINER_ID=`docker create --platform=${{ matrix.platform }} ghcr.io/junkurihara/rust-rpxy:nightly${{ matrix.tags-suffix }}`
84-
docker cp ${CONTAINER_ID}:/rpxy/bin/rpxy /tmp/${TARGET_NAME}
85-
cd /tmp
86-
echo "artifact=${TARGET_NAME}" >> $GITHUB_OUTPUT
93+
CONTAINER_ID=`docker create --platform=${{ matrix.platform }} ghcr.io/junkurihara/rust-rpxy:${{ steps.set-env.outputs.build_img }}${{ matrix.tags-suffix }}`
94+
docker cp ${CONTAINER_ID}:/rpxy/bin/rpxy /tmp/${{ steps.set-env.outputs.target_name }}
8795
8896
- name: "upload artifacts"
8997
uses: actions/upload-artifact@v3
9098
with:
91-
name: ${{ steps.extract-binary.outputs.artifact }}
92-
path: "/tmp/${{ steps.extract-binary.outputs.artifact }}"
99+
name: ${{ steps.set-env.outputs.target_name }}
100+
path: "/tmp/${{ steps.set-env.outputs.target_name }}"
93101

94102
on-failure:
95103
runs-on: ubuntu-latest
96-
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
104+
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'failure' }}
97105
steps:
98106
- run: echo 'The release triggering workflows failed'
99107

100108
release:
101109
runs-on: ubuntu-latest
102-
if: startsWith(github.ref, 'refs/tags/')
110+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true }}
103111
needs: on-success
104112
steps:
113+
- name: check pull_request title
114+
uses: actions-ecosystem/action-regex-match@v2
115+
id: regex-match
116+
with:
117+
text: ${{ github.event.pull_request.title }}
118+
regex: "^(\\d+\\.\\d+\\.\\d+)$"
119+
105120
- name: checkout
121+
if: ${{ steps.regex-match.outputs.match != '' }}
106122
uses: actions/checkout@v4
107123

108124
- name: download artifacts
125+
if: ${{ steps.regex-match.outputs.match != ''}}
109126
uses: actions/download-artifact@v3
110127
with:
111128
path: /tmp/rpxy
112129

113130
- name: make tar.gz of assets
131+
if: ${{ steps.regex-match.outputs.match != ''}}
114132
run: |
115133
mkdir /tmp/assets
116134
cd /tmp/rpxy
117135
for i in ./*; do sh -c "cd $i && tar zcvf $i.tar.gz $i && mv $i.tar.gz /tmp/assets/"; done
118136
ls -lha /tmp/assets
119137
120138
- name: release
139+
if: ${{ steps.regex-match.outputs.match != ''}}
121140
uses: softprops/action-gh-release@v1
122-
if: startsWith(github.ref, 'refs/tags/')
123141
with:
124142
files: /tmp/assets/*.tar.gz
125-
tag_name: ${{ github.ref }}
143+
name: ${{ github.event.pull_request.title }}
144+
tag_name: ${{ github.event.pull_request.title }}
145+
body: ${{ github.event.pull_request.body }}
126146
draft: true
127147
prerelease: false
128148
generate_release_notes: true

0 commit comments

Comments
 (0)