|
| 1 | +on: [ push, pull_request, workflow_dispatch ] |
| 2 | + |
| 3 | +jobs: |
| 4 | + prep: |
| 5 | + runs-on: ubuntu-latest |
| 6 | + name: Prepare build |
| 7 | + steps: |
| 8 | + - name: Extract tag/branch variables |
| 9 | + shell: bash |
| 10 | + run: | |
| 11 | + echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/tags/}|grep -v '/')" |
| 12 | + echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/}|grep -v '/')" |
| 13 | + id: extract |
| 14 | + outputs: |
| 15 | + tag: ${{ steps.extract.outputs.tag }} |
| 16 | + branch: ${{ steps.extract.outputs.branch }} |
| 17 | + |
| 18 | + build: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + name: Build packages |
| 21 | + needs: prep |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v2 |
| 24 | + - name: Set up build tools |
| 25 | + run: ./.github/workflows/setup.sh |
| 26 | + - name: Run build |
| 27 | + run: | |
| 28 | + ./setup.sh |
| 29 | + for i in build-*.sh |
| 30 | + do |
| 31 | + ./$i || exit 1 |
| 32 | + done |
| 33 | + - name: Create checksums |
| 34 | + run: | |
| 35 | + cd output/packages |
| 36 | + for i in * |
| 37 | + do |
| 38 | + md5sum -b $i > ../checksums/$i.md5 |
| 39 | + sha512sum -b $i > ../checksums/$i.sha |
| 40 | + done |
| 41 | + - name: Upload build artifacts |
| 42 | + uses: actions/upload-artifact@v2 |
| 43 | + with: |
| 44 | + name: build-artifacts |
| 45 | + path: | |
| 46 | + output/packages/* |
| 47 | + output/checksums/* |
| 48 | +
|
| 49 | + validate_build: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + name: List build content if not tagged |
| 52 | + needs: [ prep, build ] |
| 53 | + if: ${{ needs.prep.outputs.tag == '' }} |
| 54 | + steps: |
| 55 | + - name: Download artifacts |
| 56 | + uses: actions/download-artifact@v2 |
| 57 | + with: |
| 58 | + name: build-artifacts |
| 59 | + - name: List artifacts |
| 60 | + run: ls -lR |
| 61 | + |
| 62 | + publish_tag: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + name: Publish to github if tag |
| 65 | + needs: [ prep, build ] |
| 66 | + if: ${{ needs.prep.outputs.tag != '' }} |
| 67 | + steps: |
| 68 | + - name: Download artifacts |
| 69 | + uses: actions/download-artifact@v2 |
| 70 | + with: |
| 71 | + name: build-artifacts |
| 72 | + - name: Create Release |
| 73 | + id: create_release |
| 74 | + uses: actions/create-release@v1 |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + with: |
| 78 | + tag_name: ${{ github.ref }} |
| 79 | + release_name: Release ${{ github.ref }} |
| 80 | + draft: false |
| 81 | + - name: Upload packages |
| 82 | + uses: actions/github-script@v3 |
| 83 | + with: |
| 84 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 85 | + script: | |
| 86 | + const path = require('path'); |
| 87 | + const fs = require('fs'); |
| 88 | + const release_id = '${{ steps.create_release.outputs.id }}'; |
| 89 | + for (let file of await fs.readdirSync('./packages/')) { |
| 90 | + console.log('uploadReleaseAsset', file); |
| 91 | + await github.repos.uploadReleaseAsset({ |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + release_id: release_id, |
| 95 | + name: file, |
| 96 | + data: await fs.readFileSync(`./packages/${file}`) |
| 97 | + }); |
| 98 | + } |
| 99 | + - name: Upload checksums |
| 100 | + uses: actions/github-script@v3 |
| 101 | + with: |
| 102 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 103 | + script: | |
| 104 | + const path = require('path'); |
| 105 | + const fs = require('fs'); |
| 106 | + const release_id = '${{ steps.create_release.outputs.id }}'; |
| 107 | + for (let file of await fs.readdirSync('./checksums/')) { |
| 108 | + console.log('uploadReleaseAsset', file); |
| 109 | + await github.repos.uploadReleaseAsset({ |
| 110 | + owner: context.repo.owner, |
| 111 | + repo: context.repo.repo, |
| 112 | + release_id: release_id, |
| 113 | + name: file, |
| 114 | + data: await fs.readFileSync(`./checksums/${file}`) |
| 115 | + }); |
| 116 | + } |
0 commit comments