Skip to content

Publish common library as Maven artifact on release #1

Publish common library as Maven artifact on release

Publish common library as Maven artifact on release #1

# Copyright 2024 The Cross-Media Measurement Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
on:
release:
workflow_dispatch:
inputs:
base-version:
description: Base artifact version, which will be suffixed with "-SNAPSHOT"
required: true
pull_request:
types: [ opened, synchronize, edited ]
jobs:
publish-artifacts:
name: Publish Maven artifacts
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- id: get-version
env:
BASE_VERSION: ${{ inputs.base-version }}
run: |
define artifact_version
if [[ "$GITHUB_EVENT_NAME" == 'release' ]]; then
artifact_version="${GITHUB_REF_NAME#v}"
else
artifact_version="${BASE_VERSION}-SNAPSHOT"
fi
echo "artifact-version=${artifact_version}" >> "$GITHUB_OUTPUT"
- name: Set up Bazel
run: |
mkdir -p ~/.local/bin
bazelisk_path="$(which bazelisk)"
ln -s "${bazelisk_path}" ~/.local/bin/bazel
- name: Write ~/.bazelrc
run: |
echo 'common --config=ci' >> ~/.bazelrc
# Patch MODULE.bazel and MODULE.bazel.lock to specify version.
# TODO(bazelbuild/bazel#22919): Use alternative mechanism when available.
- name: Patch module version
env:
ARTIFACT_VERSION=${{ steps.get-version.outputs.artifact-version }}
run: |
match='name = "common-jvm",'
sed -i "s/${match}/${match}\n version = \"${ARTIFACT_VERSION}\"/," MODULE.bazel
module_hash="$(sha256sum MODULE.bazel | cut -d ' ' -f 1)"
match='"moduleFileHash": "[^"]\+"'
sed -i "s/${match}/\"moduleFileHash\": \"${module_hash}\"/" MODULE.bazel.lock
- name: Echo diff
run: git diff