Release #133
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
# Credits: workflow inspired from | |
# https://github.com/grain-lang/binaryen.ml/blob/master/.github/workflows/release.yml | |
# then slightly adapted, using: | |
# - https://github.com/googleapis/release-please#readme | |
# - https://github.com/google-github-actions/release-please-action/blob/main/action.yml | |
# - https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_run | |
# - https://docs.github.com/en/actions/advanced-guides/storing-workflow-data-as-artifacts | |
# - https://github.com/dawidd6/action-download-artifact#readme | |
# - https://hub.github.com/hub-release.1.html | |
on: | |
workflow_run: | |
workflows: ["Generate static binaries"] | |
branches: ["master"] | |
types: ["completed"] | |
# TODO: dispatch? | |
jobs: | |
release-please: | |
name: Create Release | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' && github.repository == 'ocaml-sf/learn-ocaml'}} | |
outputs: | |
release_created: ${{ steps.release.outputs.release_created }} | |
upload_url: ${{ steps.release.outputs.upload_url }} | |
tag_name: ${{ steps.release.outputs.tag_name }} | |
body: ${{ steps.release.outputs.body }} | |
steps: | |
- uses: google-github-actions/release-please-action@v3 | |
id: release | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
release-type: ocaml | |
package-name: learn-ocaml | |
bump-minor-pre-major: true | |
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"revert","section":"Reverts","hidden":false},{"type":"perf","section":"Performance Improvements","hidden":false},{"type":"refactor","section":"Code Refactoring","hidden":false},{"type":"deps","section":"Dependencies","hidden":false},{"type":"build","section":"Build System","hidden":false},{"type":"test","section":"Tests","hidden":false},{"type":"ci","section":"CI/CD","hidden":false},{"type":"docs","section":"Documentation","hidden":false},{"type":"style","section":"Style","hidden":true},{"type":"chore","section":"Miscellaneous Chores","hidden":true}]' | |
add-binaries: | |
needs: [release-please] | |
if: ${{ needs.release-please.outputs.release_created }} | |
name: Add archive and binaries to release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
# Mandatory step (otherwise, hub raises "fatal: Not a git repository") | |
uses: actions/checkout@v3 | |
- name: Download workflow artifacts | |
# cf. https://github.com/actions/download-artifact/issues/3 | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: static-builds.yml | |
workflow_conclusion: success | |
commit: ${{ github.sha }} | |
path: artifacts | |
- name: Unpack workflow artifacts | |
run: | | |
cd artifacts | |
mkdir -v target | |
dist=(linux darwin) | |
artifact() { printf "learn-ocaml-%s-x86_64.tar.gz" "$d"; } | |
for d in "${dist[@]}"; do | |
mkdir -v -- "$d" | |
( cd "$d" && tar xvzf "../$(artifact "$d")/$(artifact "$d")" ) | |
bin=(./learn-ocaml-client ./learn-ocaml-server ./learn-ocaml) | |
for b in "${bin[@]}"; do | |
mv -v -- "$d/$b" "target/$b-$d-x86_64" | |
done | |
done | |
mv -v -- learn-ocaml-www.zip target/learn-ocaml-www.zip | |
- name: Add binaries to release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | |
hub release edit $(find artifacts/target -type f -printf "-a %p ") -m "" "${{ needs.release-please.outputs.tag_name }}" | |
opam-release: | |
needs: [release-please] | |
if: ${{ needs.release-please.outputs.release_created }} | |
name: Publish to opam registry | |
env: | |
# Can be changed for debugging | |
source_repo: "ocaml-sf/learn-ocaml" | |
opam_repo: "ocaml/opam-repository" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Setup bot user | |
run: | | |
git config --global user.email "37002148+proofbot@users.noreply.github.com" | |
git config --global user.name "Learn-OCaml Bot" | |
# Some hacks to make sure opam doesn't pull the repo in a way we can't deal with | |
- name: Setup opam repository | |
run: | | |
mkdir -v -p ~/.opam/plugins/opam-publish/repos/ | |
git clone https://github.com/$opam_repo ~/.opam/plugins/opam-publish/repos/${opam_repo/\//%} | |
cd ~/.opam/plugins/opam-publish/repos/${opam_repo/\//%} | |
git remote add user https://${{ secrets.OPAM_RELEASE }}@github.com/proofbot/opam-repository | |
# Set up our token because opam doesn't support env var tokens | |
- name: Setup token | |
run: | | |
mkdir -p ~/.opam/plugins/opam-publish/ | |
echo -n ${{ secrets.OPAM_RELEASE }} > ~/.opam/plugins/opam-publish/proofbot.token | |
- name: Generate CHANGES file | |
env: | |
CHANGES: ${{ needs.release-please.outputs.body }} | |
run: | | |
printf "%s" "$CHANGES" > CHANGES.md | |
# TODO: Docker-based caching | |
- name: Setup OCaml | |
uses: avsm/setup-ocaml@v1 | |
with: | |
ocaml-version: 4.12.0 | |
- name: Install opam-publish | |
run: | | |
opam install -y -j 2 opam-publish | |
- name: Install expect | |
run: | | |
sudo apt-get update -y -q | |
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends expect | |
- name: Publish to opam | |
run: | | |
./scripts/opam-publish.exp "${{ needs.release-please.outputs.tag_name }}" "$opam_repo" "$source_repo" | |
# Note: you may want to update the jobs below and deploy-master.yml at once | |
push_server: | |
needs: [release-please] | |
if: ${{ needs.release-please.outputs.release_created }} | |
name: Push learn-ocaml image to Docker Hub | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get tag name | |
run: tag="${{ needs.release-please.outputs.tag_name }}"; echo "::set-output name=tag::${tag#v}" | |
id: tag | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Push to Docker Hub | |
uses: docker/build-push-action@v1 | |
with: | |
always_pull: true | |
add_git_labels: true | |
labels: "org.opencontainers.image.version=${{ steps.tag.outputs.tag }}" | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
repository: ocamlsf/learn-ocaml | |
tags: "latest,${{ steps.tag.outputs.tag }}" | |
push_client: | |
needs: [release-please] | |
if: ${{ needs.release-please.outputs.release_created }} | |
name: Push learn-ocaml-client image to Docker Hub | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get tag name | |
run: tag="${{ needs.release-please.outputs.tag_name }}"; echo "::set-output name=tag::${tag#v}" | |
id: tag | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Push to Docker Hub | |
uses: docker/build-push-action@v1 | |
with: | |
always_pull: true | |
add_git_labels: true | |
labels: "org.opencontainers.image.version=${{ steps.tag.outputs.tag }}" | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
repository: ocamlsf/learn-ocaml-client | |
target: client | |
tags: "latest,${{ steps.tag.outputs.tag }}" | |
push_emacs_client: | |
needs: | |
- release-please | |
- push_client | |
if: ${{ needs.release-please.outputs.release_created }} | |
name: Push emacs-learn-ocaml-client image to Docker Hub | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get tag name | |
run: tag="${{ needs.release-please.outputs.tag_name }}"; echo "::set-output name=tag::${tag#v}" | |
id: tag | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Push to Docker Hub | |
# https://github.com/docker/build-push-action/tree/releases/v1#readme | |
uses: docker/build-push-action@v1 | |
with: | |
path: ci/docker-emacs-learn-ocaml-client | |
build_args: "base=ocamlsf/learn-ocaml-client,version=${{ steps.tag.outputs.tag }}" | |
always_pull: true | |
add_git_labels: true | |
labels: "org.opencontainers.image.version=${{ steps.tag.outputs.tag }}" | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
repository: ocamlsf/emacs-learn-ocaml-client | |
tags: ${{ steps.tag.outputs.tag }} |