Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rabbitmq bzlmod release automation #33

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/publish-rabbitmq-bcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Add to rabbitmq/bazel-central-registry@erlang-packages
on:
release:
types: [published]
workflow_dispatch:
jobs:
add-module:
runs-on: ubuntu-latest
steps:
- name: CHECKOUT
uses: actions/checkout@v3
with:
path: looking_glass
- name: CHECKOUT rabbitmq/bazel-central-registry@erlang-packages
uses: actions/checkout@v3
with:
repository: rabbitmq/bazel-central-registry
path: bazel-central-registry
ref: erlang-packages
- name: PUBLISH TO rabbitmq/bazel-central-registry@erlang-packages
working-directory: bazel-central-registry
env:
MODULE_NAME: com_github_rabbitmq_looking_glass
REPO_NAME: looking_glass
run: |
VERSION="${{ github.ref_name }}"
MAJOR="${VERSION:0:1}"

echo "VERSION: ${VERSION}"
echo "MAJOR: ${MAJOR}"

cat << EOF > ${MODULE_NAME}.json
{
"build_file": null,
"build_targets": [
"@${MODULE_NAME}//:${MODULE_NAME}",
"@${MODULE_NAME}//:erlang_app"
],
"compatibility_level": "$((${MAJOR} + 1))",
"deps": [],
"module_dot_bazel": "${{ github.workspace }}/${REPO_NAME}/MODULE.bazel",
"name": "${MODULE_NAME}",
"patch_strip": 0,
"patches": [],
"presubmit_yml": "${{ github.workspace }}/${REPO_NAME}/.bcr/presubmit.yml",
"strip_prefix": "${REPO_NAME}-${VERSION}",
"test_module_build_targets": [],
"test_module_path": null,
"test_module_test_targets": [],
"url": "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/${REPO_NAME}-${VERSION}.tar.gz",
"version": "${VERSION}"
}
EOF

jq '.' ${MODULE_NAME}.json

bazel run //tools:add_module -- \
--input=${MODULE_NAME}.json

git diff
- name: CREATE PULL REQUEST
uses: peter-evans/create-pull-request@v5.0.2
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
path: bazel-central-registry
title: Add ${{ github.repository }}@${{ github.ref_name }}
body: >
Automated changes created by
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
using the [create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action in the ${{ github.workflow }} workflow.
commit-message: |
Add ${{ github.repository }}@${{ github.ref_name }}
branch: add-${{ github.repository }}@${{ github.ref_name }}
delete-branch: true
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Release
on:
push:
tags:
- 0.*
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: CHECKOUT
uses: actions/checkout@v3
with:
path: looking_glass
- name: ASSERT VERSIONS
id: versions
working-directory: looking_glass
run: |
sudo npm install --global --silent @bazel/buildozer

VERSION_ERLANG_MK="$(sed -ne 's/PROJECT_VERSION = \(.*\)/\1/p' Makefile)"

if [[ "${{ github.ref_name }}" != "$VERSION_ERLANG_MK" ]]; then
echo "Version in Makefile ($VERSION_ERLANG_MK) does not match tag (${{ github.ref_name }})"
exit 1
fi

VERSION_BAZEL="$(cat MODULE.bazel | buildozer 'print version' -:%module)"

if [[ "${{ github.ref_name }}" != "$VERSION_BAZEL" ]]; then
echo "Version in MODULE.bazel ($VERSION_BAZEL) does not match tag (${{ github.ref_name }})"
exit 1
fi

echo "version=$VERSION_BAZEL" | tee -a $GITHUB_OUTPUT
- name: FETCH THE SOURCE ARCHIVE
run: |
curl \
-L \
-o looking_glass-${{ steps.versions.outputs.version }}.tar.gz \
https://github.com/${{ github.repository }}/archive/${{ github.ref }}.tar.gz
- name: CREATE RELEASE
id: create-release
uses: ncipollo/release-action@v1.12.0
with:
allowUpdates: true
artifactErrorsFailBuild: true
updateOnlyUnreleased: true
generateReleaseNotes: true
artifacts: >-
looking_glass-${{ steps.versions.outputs.version }}.tar.gz