From 4354cab7e379e931c0fbb0f78005a081ca11e189 Mon Sep 17 00:00:00 2001 From: Gent Semaj Date: Wed, 6 Apr 2022 18:24:34 -0400 Subject: [PATCH] Add CI/CD step to upload artifacts off-site (#244) * Download and list artifacts after build * Add commit hash + file extension to artifact name * Initial SSH implementation * Don't build artifacts for PRs * Fetch endpoint from secret * Zip artifacts before uploading to CDN * Use short SHA in archive names --- .github/workflows/check-builds.yaml | 41 +++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-builds.yaml b/.github/workflows/check-builds.yaml index 5d3ded5..e1a2683 100644 --- a/.github/workflows/check-builds.yaml +++ b/.github/workflows/check-builds.yaml @@ -13,6 +13,9 @@ jobs: ubuntu-build: runs-on: ubuntu-latest steps: + - name: Set environment + run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV + shell: bash - uses: actions/checkout@v2 with: submodules: recursive @@ -42,12 +45,15 @@ jobs: - name: Upload build artifact uses: actions/upload-artifact@v2 with: - name: ubuntu20_04-bin-x64 + name: 'ubuntu20_04-bin-x64-${{ env.SHORT_SHA }}' path: bin windows-build: runs-on: windows-2019 steps: + - name: Set environment + run: $s = $env:GITHUB_SHA.subString(0, 7); echo "SHORT_SHA=$s" >> $env:GITHUB_ENV + shell: pwsh - uses: actions/checkout@v2 with: submodules: recursive @@ -92,5 +98,36 @@ jobs: - name: Upload build artifact uses: actions/upload-artifact@v2 with: - name: windows-vs2019-bin-x64 + name: 'windows-vs2019-bin-x64-${{ env.SHORT_SHA }}' path: bin + + copy-artifacts: + if: github.event_name != 'pull_request' + runs-on: ubuntu-latest + needs: [windows-build, ubuntu-build] + env: + BOT_SSH_KEY: ${{ secrets.BOT_SSH_KEY }} + ENDPOINT: ${{ secrets.ENDPOINT }} + steps: + - run: mkdir ${{ github.sha }} + - uses: actions/download-artifact@v3 + with: + path: ${{ github.sha }} + - name: Prepare artifacts + shell: bash + run: | + sudo apt install zip -y + cd ${{ github.sha }} + for build in *; do + cd $build + zip ../$build.zip * + cd .. + rm -r $build + done + cd .. + - name: Upload artifacts + shell: bash + run: | + umask 077 + printf %s "$BOT_SSH_KEY" > cdn_key + scp -i cdn_key -o StrictHostKeyChecking=no -r ${{ github.sha }} $ENDPOINT