From e493e0033a4581a8bd3dcdd63e3ec9d3fc1d421c Mon Sep 17 00:00:00 2001 From: Yihau Chen Date: Fri, 13 May 2022 17:10:03 +0800 Subject: [PATCH] chore: build windows artifacts on Github Actions (#25188) * chore: always checkout repo from master * chore: rename variable tag => commit * chore: gh-release when tag is present * chore: add release-artifacts-auto * chore: skip build when channel is empty * chore: use GITHUB_REF_NAME as CI_BRANCH --- .github/workflows/release-artifacts-auto.yml | 19 +++++++++++ .../workflows/release-artifacts-manually.yml | 6 ++-- .github/workflows/release-artifacts.yml | 34 ++++++++++++++----- ci/env.sh | 7 +--- 4 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/release-artifacts-auto.yml diff --git a/.github/workflows/release-artifacts-auto.yml b/.github/workflows/release-artifacts-auto.yml new file mode 100644 index 000000000..fbf5bfe01 --- /dev/null +++ b/.github/workflows/release-artifacts-auto.yml @@ -0,0 +1,19 @@ +name: release-artifacts-auto + +on: + push: + branches: + - master + - v[0-9]+.[0-9]+ + tags: + - v[0-9]+.[0-9]+.[0-9] + +jobs: + release-artifacts: + uses: ./.github/workflows/release-artifacts.yml + with: + commit: ${{ github.sha }} + secrets: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} diff --git a/.github/workflows/release-artifacts-manually.yml b/.github/workflows/release-artifacts-manually.yml index 242c60cd2..35de72922 100644 --- a/.github/workflows/release-artifacts-manually.yml +++ b/.github/workflows/release-artifacts-manually.yml @@ -3,16 +3,16 @@ name: release-artifacts-manually on: workflow_dispatch: inputs: - tag: + commit: type: string required: true - description: tag + description: commit jobs: release-artifacts: uses: ./.github/workflows/release-artifacts.yml with: - tag: ${{ github.event.inputs.tag }} + commit: ${{ github.event.inputs.commit }} secrets: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml index 7c7f614e9..400dcb1d9 100644 --- a/.github/workflows/release-artifacts.yml +++ b/.github/workflows/release-artifacts.yml @@ -3,7 +3,7 @@ name: release-artifacts on: workflow_call: inputs: - tag: + commit: required: false type: string secrets: @@ -17,10 +17,14 @@ on: jobs: windows-build: runs-on: windows-2022 + outputs: + tag: ${{ steps.build.outputs.tag }} + channel: ${{ steps.build.outputs.channel }} steps: - name: Checkout uses: actions/checkout@v3 with: + ref: master fetch-depth: 0 - name: Setup Rust @@ -35,30 +39,41 @@ jobs: cp -r ci/env.sh /tmp/env.sh - name: Switch Version - if: ${{ inputs.tag }} + if: ${{ inputs.commit }} run: | - git checkout ${{ inputs.tag }} + git checkout ${{ inputs.commit }} - name: Build + id: build shell: bash run: | choco install openssl export OPENSSL_DIR="C:\Program Files\OpenSSL-Win64" choco install protoc source /tmp/env.sh + echo "::set-output name=tag::$CI_TAG" + eval "$(ci/channel-info.sh)" + echo "::set-output name=channel::$CHANNEL" ci/publish-tarball.sh - mkdir -p "github-action-s3-upload/${{ inputs.tag }}" - cp -v "solana-release-x86_64-pc-windows-msvc.tar.bz2" "github-action-s3-upload/${{ inputs.tag }}/" - cp -v "solana-release-x86_64-pc-windows-msvc.yml" "github-action-s3-upload/${{ inputs.tag }}/" - cp -v "solana-install-init-x86_64-pc-windows-msvc"* "github-action-s3-upload/${{ inputs.tag }}/" + + - name: Prepare Upload Files + if: ${{ steps.build.outputs.channel != '' || steps.build.outputs.tag != '' }} + shell: bash + run: | + mkdir -p "github-action-s3-upload/${{ inputs.commit }}" + cp -v "solana-release-x86_64-pc-windows-msvc.tar.bz2" "github-action-s3-upload/${{ inputs.commit }}/" + cp -v "solana-release-x86_64-pc-windows-msvc.yml" "github-action-s3-upload/${{ inputs.commit }}/" + cp -v "solana-install-init-x86_64-pc-windows-msvc"* "github-action-s3-upload/${{ inputs.commit }}/" - name: Upload Artifacts + if: ${{ steps.build.outputs.channel != '' || steps.build.outputs.tag != '' }} uses: actions/upload-artifact@v3 with: name: windows-artifact path: github-action-s3-upload/ windows-s3-upload: + if: ${{ needs.windows-build.outputs.channel != '' || needs.windows-build.outputs.tag != '' }} needs: [windows-build] runs-on: ubuntu-20.04 steps: @@ -80,6 +95,7 @@ jobs: SOURCE_DIR: "github-action-s3-upload" windows-gh-release: + if: ${{ needs.windows-build.outputs.tag != '' }} needs: [windows-build] runs-on: ubuntu-20.04 steps: @@ -92,7 +108,7 @@ jobs: - name: Release uses: softprops/action-gh-release@v1 with: - tag_name: ${{ inputs.tag }} + tag_name: ${{ inputs.commit }} draft: true files: | - github-action-s3-upload/${{ inputs.tag }}/* + github-action-s3-upload/${{ inputs.commit }}/* diff --git a/ci/env.sh b/ci/env.sh index 35f8bc754..131bfb88f 100644 --- a/ci/env.sh +++ b/ci/env.sh @@ -86,16 +86,11 @@ if [[ -n $CI ]]; then export CI_BUILD_ID=$GITHUB_RUN_ID export CI_JOB_ID=$GITHUB_RUN_NUMBER export CI_REPO_SLUG=$GITHUB_REPOSITORY + export CI_BRANCH=$GITHUB_REF_NAME CI_COMMIT=$(git rev-parse HEAD) export CI_COMMIT - CI_BRANCH=$(git rev-parse --abbrev-ref HEAD) - if [[ $CI_BRANCH == "HEAD" ]]; then - CI_BRANCH="" - fi - export CI_BRANCH - CI_TAG=$(git tag --points-at HEAD) export CI_TAG