diff --git a/.github/workflows/docker_build_push.yml b/.github/workflows/docker_build_push.yml index 8aa089fa..b320a84b 100644 --- a/.github/workflows/docker_build_push.yml +++ b/.github/workflows/docker_build_push.yml @@ -1,11 +1,12 @@ -name: Build and publish docker +name: Build and publish docker, and trigger release on: push: branches: - "develop" - - "main" - tags: - - "*.*.*" + pull_request: + types: [closed] + branches: + - main env: GHCR: ghcr.io @@ -15,6 +16,7 @@ env: jobs: build_and_push: runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} || ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true }} strategy: fail-fast: false matrix: @@ -167,3 +169,14 @@ jobs: cache-to: type=gha,mode=max,scope=rpxy-latest-${{ matrix.target }} platforms: ${{ matrix.platforms }} labels: ${{ steps.meta.outputs.labels }} + + dispatch_release_event: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref == 'develop' && github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true }} + needs: build_and_push + steps: + - name: Repository dispatch for release + uses: peter-evans/repository-dispatch@v2 + with: + event-type: release-event + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "pull_request": { "title": "${{ github.event.pull_request.title }}", "body": "${{ github.event.pull_request.body }}", "number": "${{ github.event.pull_request.number }}", "head": "${{ github.event.pull_request.head.ref }}", "base": "${{ github.event.pull_request.base.ref}}"}}' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ec075c59..93ab5495 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,11 +5,17 @@ on: - "Build and publish docker" types: - "completed" + branches: + - main + - develop + repository_dispatch: + types: + - release-event jobs: on-success: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} + if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'repositry_dispatch' }} strategy: fail-fast: false matrix: @@ -70,47 +76,58 @@ jobs: steps: - run: "echo 'The relese triggering workflows passed'" + - name: "set env" + id: "set-env" run: | - if [ ${{ matrix.platform }} = "linux/amd64" ];then PLATFORM_MAP="x86_64";else PLATFORM_MAP="aarch64";fi - if [ ${{ github.ref_name == 'develop' }} ];then BUILD_NAME="rpxy-nightly";else BUILD_NAME="rpxy";fi - echo "PLATFORM_MAP=${PLATFORM_MAP}" >> $GITHUB_ENV - echo "TARGET_NAME=${BUILD_NAME}-${PLATFORM_MAP}-unknown-linux-${{ matrix.target }}${{ matrix.build-feature }}" >> $GITHUB_ENV + if [ ${{ matrix.platform }} == 'linux/amd64' ]; then PLATFORM_MAP="x86_64"; else PLATFORM_MAP="aarch64"; fi + if [ ${{ github.ref_name }} == 'develop' ]; then BUILD_NAME="-nightly"; else BUILD_NAME=""; fi + if [ ${{ github.ref_name }} == 'develop' ]; then BUILD_IMG="nightly"; else BUILD_IMG="latest"; fi + echo "build_img=${BUILD_IMG}" >> $GITHUB_OUTPUT + echo "target_name=rpxy${BUILD_NAME}-${PLATFORM_MAP}-unknown-linux-${{ matrix.target }}${{ matrix.build-feature }}" >> $GITHUB_OUTPUT - name: "docker pull and extract binary from docker image" id: "extract-binary" run: | - CONTAINER_ID=`docker create --platform=${{ matrix.platform }} ghcr.io/junkurihara/rust-rpxy:nightly${{ matrix.tags-suffix }}` - docker cp ${CONTAINER_ID}:/rpxy/bin/rpxy /tmp/${TARGET_NAME} - cd /tmp - echo "artifact=${TARGET_NAME}" >> $GITHUB_OUTPUT + CONTAINER_ID=`docker create --platform=${{ matrix.platform }} ghcr.io/junkurihara/rust-rpxy:${{ steps.set-env.outputs.build_img }}${{ matrix.tags-suffix }}` + docker cp ${CONTAINER_ID}:/rpxy/bin/rpxy /tmp/${{ steps.set-env.outputs.target_name }} - name: "upload artifacts" uses: actions/upload-artifact@v3 with: - name: ${{ steps.extract-binary.outputs.artifact }} - path: "/tmp/${{ steps.extract-binary.outputs.artifact }}" + name: ${{ steps.set-env.outputs.target_name }} + path: "/tmp/${{ steps.set-env.outputs.target_name }}" on-failure: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'failure' }} + if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'failure' }} steps: - run: echo 'The release triggering workflows failed' release: runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') + if: ${{ github.event_name == 'repository_dispatch' }} needs: on-success steps: + - name: check pull_request title + uses: kaisugi/action-regex-match@v1.0.0 + id: regex-match + with: + text: ${{ github.event.client_payload.pull_request.title }} + regex: "^(\\d+\\.\\d+\\.\\d+)$" + - name: checkout + if: ${{ steps.regex-match.outputs.match != '' }} uses: actions/checkout@v4 - name: download artifacts + if: ${{ steps.regex-match.outputs.match != ''}} uses: actions/download-artifact@v3 with: path: /tmp/rpxy - name: make tar.gz of assets + if: ${{ steps.regex-match.outputs.match != ''}} run: | mkdir /tmp/assets cd /tmp/rpxy @@ -118,11 +135,13 @@ jobs: ls -lha /tmp/assets - name: release + if: ${{ steps.regex-match.outputs.match != ''}} uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') with: files: /tmp/assets/*.tar.gz - tag_name: ${{ github.ref }} + name: ${{ github.event.client_payload.pull_request.title }} + tag_name: ${{ github.event.client_payload.pull_request.title }} + body: ${{ github.event.client_payload.pull_request.body }} draft: true prerelease: false generate_release_notes: true diff --git a/.github/workflows/shift_left.yml b/.github/workflows/shift_left.yml index 32f526c3..48e0c183 100644 --- a/.github/workflows/shift_left.yml +++ b/.github/workflows/shift_left.yml @@ -1,6 +1,9 @@ name: ShiftLeft Scan -on: push +on: + push: + pull_request: + types: [synchronize, opened] jobs: Scan-Build: