|
| 1 | +name: Release |
| 2 | +# Credits: workflow inspired from |
| 3 | +# https://github.com/grain-lang/binaryen.ml/blob/master/.github/workflows/release.yml |
| 4 | +# then slightly adapted, using: |
| 5 | +# - https://github.com/googleapis/release-please#readme |
| 6 | +# - https://github.com/google-github-actions/release-please-action/blob/main/action.yml |
| 7 | +# - https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_run |
| 8 | +# - https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts |
| 9 | +# - https://github.com/dawidd6/action-download-artifact#readme |
| 10 | +# - https://hub.github.com/hub-release.1.html |
| 11 | +on: |
| 12 | + workflow_run: |
| 13 | + workflows: ["Generate static binaries"] |
| 14 | + branches: ["master"] |
| 15 | + types: ["completed"] |
| 16 | + # TODO: dispatch? |
| 17 | + |
| 18 | +jobs: |
| 19 | + release-please: |
| 20 | + name: Create Release |
| 21 | + runs-on: ubuntu-latest |
| 22 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 23 | + outputs: |
| 24 | + release_created: ${{ steps.release.outputs.release_created }} |
| 25 | + upload_url: ${{ steps.release.outputs.upload_url }} |
| 26 | + tag_name: ${{ steps.release.outputs.tag_name }} |
| 27 | + body: ${{ steps.release.outputs.body }} |
| 28 | + steps: |
| 29 | + - uses: GoogleCloudPlatform/release-please-action@v2 |
| 30 | + id: release |
| 31 | + with: |
| 32 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + release-type: ocaml |
| 34 | + package-name: learn-ocaml |
| 35 | + bump-minor-pre-major: true |
| 36 | + |
| 37 | + add-binaries: |
| 38 | + needs: [release-please] |
| 39 | + if: ${{ needs.release-please.outputs.release_created }} |
| 40 | + name: Add archive and binaries to release |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - name: Check out the repo |
| 44 | + # Mandatory step (otherwise, hub raises "fatal: Not a git repository") |
| 45 | + uses: actions/checkout@v2 |
| 46 | + - name: Download workflow artifacts |
| 47 | + # cf. https://github.com/actions/download-artifact/issues/3 |
| 48 | + uses: dawidd6/action-download-artifact@v2 |
| 49 | + with: |
| 50 | + workflow: static-builds.yml |
| 51 | + workflow_conclusion: success |
| 52 | + commit: ${{ github.sha }} |
| 53 | + path: artifacts |
| 54 | + - name: Unpack workflow artifacts |
| 55 | + run: | |
| 56 | + cd artifacts |
| 57 | + mkdir -v target |
| 58 | + dist=(linux darwin) |
| 59 | + artifact() { printf "learn-ocaml-%s-x86_64.tar.gz" "$d"; } |
| 60 | + for d in "${dist[@]}"; do |
| 61 | + mkdir -v -- "$d" |
| 62 | + ( cd "$d" && tar xvzf "../$(artifact "$d")/$(artifact "$d")" ) |
| 63 | + bin=(./learn-ocaml-client ./learn-ocaml-server ./learn-ocaml) |
| 64 | + for b in "${bin[@]}"; do |
| 65 | + mv -v -- "$d/$b" "target/$b-$d-x86_64" |
| 66 | + done |
| 67 | + done |
| 68 | + - name: Add binaries to release |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + run: |
| 72 | + hub release edit $(find artifacts/target -type f -printf "-a %p ") -m "" "${{ needs.release-please.outputs.tag_name }}" |
| 73 | + |
| 74 | + opam-release: |
| 75 | + needs: [release-please] |
| 76 | + if: ${{ needs.release-please.outputs.release_created }} |
| 77 | + name: Publish to opam registry |
| 78 | + env: |
| 79 | + # Can be changed for debugging |
| 80 | + source_repo: "ocaml-sf/learn-ocaml" |
| 81 | + opam_repo: "ocaml/opam-repository" |
| 82 | + runs-on: ubuntu-latest |
| 83 | + steps: |
| 84 | + - name: Check out the repo |
| 85 | + uses: actions/checkout@v2 |
| 86 | + - name: Setup bot user |
| 87 | + run: | |
| 88 | + git config --global user.email "[email protected]" |
| 89 | + git config --global user.name "Learn-OCaml Bot" |
| 90 | + # Some hacks to make sure opam doesn't pull the repo in a way we can't deal with |
| 91 | + - name: Setup opam repository |
| 92 | + run: | |
| 93 | + mkdir -v -p ~/.opam/plugins/opam-publish/repos/ |
| 94 | + git clone git://github.com/$opam_repo ~/.opam/plugins/opam-publish/repos/${opam_repo/\//%} |
| 95 | + cd ~/.opam/plugins/opam-publish/repos/${opam_repo/\//%} |
| 96 | + git remote add user https://${{ secrets.OPAM_RELEASE }}@github.com/proofbot/opam-repository |
| 97 | + # Set up our token because opam doesn't support env var tokens |
| 98 | + - name: Setup token |
| 99 | + run: | |
| 100 | + mkdir -p ~/.opam/plugins/opam-publish/ |
| 101 | + echo -n ${{ secrets.OPAM_RELEASE }} > ~/.opam/plugins/opam-publish/proofbot.token |
| 102 | + - name: Generate CHANGES file |
| 103 | + env: |
| 104 | + CHANGES: ${{ needs.release-please.outputs.body }} |
| 105 | + run: | |
| 106 | + printf "%s" "$CHANGES" > CHANGES.md |
| 107 | + # TODO: Docker-based caching |
| 108 | + - name: Setup OCaml |
| 109 | + uses: avsm/setup-ocaml@v1 |
| 110 | + with: |
| 111 | + ocaml-version: 4.12.0 |
| 112 | + - name: Install opam-publish |
| 113 | + run: | |
| 114 | + opam install -y -j 2 opam-publish |
| 115 | + - name: Install expect |
| 116 | + run: | |
| 117 | + sudo apt-get update -y -q |
| 118 | + sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends expect |
| 119 | + - name: Publish to opam |
| 120 | + run: | |
| 121 | + ./scripts/opam-publish.exp "${{ needs.release-please.outputs.tag_name }}" "$opam_repo" "$source_repo" |
0 commit comments