WIP Create initial workflow for publishing to Maven Central #3
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: Continuous Deployment | |
env: | |
MATRIX: '[{"OS": "ubuntu","NAMED_OS": "linux","RUNNER": "ubuntu-latest","ARCH": "x64","TARGET": "x86_64-unknown-linux-gnu","CLASSIFIER": "linux-x86_64"}, | |
{"OS": "ubuntu","NAMED_OS": "linux","RUNNER": ["self-hosted", "Linux", "ARM64"],"ARCH": "arm64","TARGET": "aarch64-unknown-linux-gnu","CLASSIFIER": "linux-aarch_64"}, | |
{"OS": "macos","NAMED_OS": "darwin","RUNNER": "macos-12","ARCH": "x64","TARGET": "x86_64-apple-darwin","CLASSIFIER": "osx-x86_64"}, | |
{"OS": "macos","NAMED_OS": "darwin","RUNNER": "macos-13-xlarge","ARCH": "arm64","TARGET": "aarch64-apple-darwin","CLASSIFIER": "osx-aarch_64"}]' | |
#, | |
#{"OS": "ubuntu","NAMED_OS": "linux","ARCH": "arm64","TARGET": "aarch64-unknown-linux-musl","RUNNER": ["self-hosted", "Linux", "ARM64"],"IMAGE": "node:alpine","CONTAINER_OPTIONS": "--user root --privileged --rm"}, | |
#{"OS": "ubuntu","NAMED_OS": "linux","ARCH": "x64","TARGET": "x86_64-unknown-linux-musl","RUNNER": "ubuntu-latest","IMAGE": "node:alpine","CONTAINER_OPTIONS": "--user root --privileged"}]' | |
on: | |
pull_request: | |
paths: | |
- .github/workflows/gradle-cd.yml | |
- .github/workflows/start-self-hosted-runner/action.yml | |
- .github/workflows/install-rust-and-protoc/action.yml | |
push: | |
tags: | |
- "v*.*" | |
concurrency: | |
group: npm-${{ github.head_ref || github.ref }} | |
cancel-in-progress: true | |
permissions: | |
id-token: write | |
jobs: | |
output-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Set matrix | |
id: set-matrix | |
run: | | |
echo "::set-output name=matrix::${{toJson( env.MATRIX )}}" | |
start-self-hosted-runner: | |
#if: github.repository_owner == 'aws' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Start self hosted EC2 runner | |
uses: ./.github/workflows/start-self-hosted-runner | |
with: | |
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
ec2-instance-id: ${{ secrets.AWS_EC2_INSTANCE_ID }} | |
publish-binaries: | |
needs: [start-self-hosted-runner, output-matrix] | |
#if: github.repository_owner == 'aws' | |
name: Publish packages to Maven Central | |
runs-on: ${{ matrix.build.RUNNER }} | |
container: | |
image: ${{ matrix.build.IMAGE || '' }} | |
options: ${{ matrix.build.CONTAINER_OPTIONS || 'none'}} | |
strategy: | |
fail-fast: false | |
matrix: | |
build: | |
${{fromJson(needs.output-matrix.outputs.matrix)}} | |
steps: | |
- name: Setup self-hosted runner access | |
if: ${{ contains(matrix.build.RUNNER, 'self-hosted') && matrix.build.TARGET != 'aarch64-unknown-linux-musl' }} | |
run: sudo chown -R $USER:$USER /home/ubuntu/actions-runner/_work/glide-for-redis | |
# For MUSL on X64 we need to install git since we use the checkout action | |
- name: Install git for musl | |
if: ${{ contains(matrix.build.TARGET, 'x86_64-unknown-linux-musl')}} | |
run: | | |
apk update | |
apk add git | |
- name: Checkout | |
if: ${{ matrix.build.TARGET != 'aarch64-unknown-linux-musl' }} | |
uses: actions/checkout@v4 | |
with: | |
submodules: "true" | |
fetch-depth: 0 | |
#- name: Setup for musl | |
# if: ${{ contains(matrix.build.TARGET, 'musl')}} | |
# uses: ./.github/workflows/setup-musl-on-linux | |
# with: | |
# workspace: $GITHUB_WORKSPACE | |
# npm-scope: ${{ vars.NPM_SCOPE }} | |
# npm-auth-token: ${{ secrets.NPM_AUTH_TOKEN }} | |
# arch: ${{ matrix.build.ARCH }} | |
- name: Set the release version | |
shell: bash | |
run: | | |
export version=`if ${{ github.event_name == 'pull_request' }}; then echo '255.255.255'; else echo ${GITHUB_REF:11}; fi` | |
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV | |
- name: Set up JDK ${{ matrix.java }} | |
uses: actions/setup-java@v4 | |
with: | |
distribution: "temurin" | |
java-version: ${{ matrix.java }} | |
- name: Install shared software dependencies | |
uses: ./.github/workflows/install-shared-dependencies | |
with: | |
os: ${{ matrix.host.OS }} | |
target: ${{ matrix.host.TARGET }} | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Install protoc (protobuf) | |
uses: arduino/setup-protoc@v3 | |
with: | |
version: "26.1" | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Update package version in config.toml | |
uses: ./.github/workflows/update-glide-version | |
with: | |
folder_path: "${{ github.workspace }}/java/.cargo" | |
named_os: ${{ matrix.build.NAMED_OS }} | |
- name: Create build.gradle file | |
shell: bash | |
working-directory: ./java/client | |
run: | | |
SED_FOR_MACOS=`if [[ "${{ inputs.os }}" =~ .*"macos".* ]]; then echo "''"; fi` | |
sed -i $SED_FOR_MACOS 's/placeholder/${{ matrix.build.CLASSIFIER }}/g' ./build.gradle | |
#- name: Build Java wrapper | |
# working-directory: java | |
# run: ./gradlew --continue build | |
- name: Publish to Maven Central | |
if: github.event_name != 'pull_request' | |
shell: bash | |
working-directory: java | |
run: | | |
./gradlew :client:publishToMavenLocal | |
# set +e | |
# Redirect only stderr | |
# { npm_publish_err=$(npm publish --access public 2>&1 >&3 3>&-); } 3>&1 | |
# if [[ "$npm_publish_err" == *"You cannot publish over the previously published versions"* ]] | |
# then | |
# echo "Skipping publishing, package already published" | |
# elif [[ ! -z "$npm_publish_err" ]] | |
# then | |
# echo "Failed to publish with error: ${npm_publish_err}" | |
# exit 1 | |
# fi | |
# env: | |
# NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
#- name: Pack the Java JAR | |
# shell: bash | |
# working-directory: ./node | |
# run: | | |
# # Remove the "cpu" and "os" fileds so the base package would be able to install it on ubuntu | |
# SED_FOR_MACOS=`if [[ "${{ matrix.build.OS }}" =~ .*"macos".* ]]; then echo "''"; fi` | |
# sed -i $SED_FOR_MACOS '/"\/\/\/cpu": \[/,/]/d' ./package.json && sed -i $SED_FOR_MACOS '/"\/\/\/os": \[/,/]/d' ./package.json | |
# mkdir -p bin | |
# npm pack --pack-destination ./bin | |
# ls ./bin | |
# env: | |
# NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
- name: Upload the JAR | |
if: github.event_name != 'pull_request' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.build.TARGET }} | |
path: ./java/client/build/libs/glide-placeholder.jar | |
if-no-files-found: error | |
# Reset the repository to make sure we get the clean checkout of the action later in other actions. | |
# It is not required since in other actions we are cleaning before the action, but it is a good practice to do it here as well. | |
- name: Reset repository | |
if: ${{ matrix.build.ARCH == 'arm64' }} | |
shell: bash | |
run: | | |
git reset --hard | |
git clean -xdf | |