Skip to content

Commit

Permalink
Add GitHub Actions workflow for pushing Dagger releases.
Browse files Browse the repository at this point in the history
Once submitted, we should be able to run this script manually from the GitHub Actions page or from the command line. See https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow

Tested this manually in presubmit:
https://github.com/google/dagger/actions/runs/1457542417

RELNOTES=N/A
PiperOrigin-RevId: 411101379
  • Loading branch information
bcorso authored and Dagger Team committed Nov 19, 2021
1 parent 75b93a0 commit 8184387
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 24 deletions.
263 changes: 263 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,263 @@
name: Dagger Release

on:
workflow_dispatch:
inputs:
dagger_release_version:
description: 'The Dagger version to use in this release.'
required: true

env:
USE_JAVA_DISTRIBUTION: 'zulu'
# Our Bazel builds currently rely on JDK 8.
USE_JAVA_VERSION: '8'
# Our Bazel builds currently rely on 4.2.1. The version is set via
# baselisk by USE_BAZEL_VERSION: https://github.com/bazelbuild/bazelisk.
USE_BAZEL_VERSION: '4.2.1'
DAGGER_RELEASE_VERSION: "${{ github.event.inputs.dagger_release_version }}"

# TODO(bcorso):Convert these jobs into local composite actions to share with the
# continuous integration workflow.
jobs:
validate-latest-dagger-version:
name: 'Validate Dagger version'
runs-on: ubuntu-latest
steps:
# Cancel previous runs on the same branch to avoid unnecessary parallel
# runs of the same job. See https://github.com/google/go-github/pull/1821
- name: Cancel previous
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}
- name: 'Check out gh-pages repository'
uses: actions/checkout@v2
with:
ref: 'refs/heads/gh-pages'
path: gh-pages
- name: 'Validate latest Dagger version'
run: ./gh-pages/.github/scripts/validate-latest-dagger-version.sh gh-pages/_config.yml
shell: bash
bazel-build:
name: 'Bazel build'
needs: validate-latest-dagger-version
runs-on: ubuntu-latest
steps:
- name: 'Install Java ${{ env.USE_JAVA_VERSION }}'
uses: actions/setup-java@v2
with:
distribution: '${{ env.USE_JAVA_DISTRIBUTION }}'
java-version: '${{ env.USE_JAVA_VERSION }}'
- name: 'Check out repository'
uses: actions/checkout@v2
- name: 'Cache Bazel files'
uses: actions/cache@v2
with:
path: ~/.cache/bazel
key: ${{ runner.os }}-bazel-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-bazel-build-
- name: 'Java build'
run: bazel build //java/...
shell: bash
- name: 'Install local snapshot'
run: ./util/install-local-snapshot.sh
shell: bash
- name: 'Upload local snapshot for tests'
uses: actions/upload-artifact@v2
with:
name: local-snapshot
path: ~/.m2/repository/com/google/dagger
- name: 'Clean bazel cache'
# According to the documentation, we should be able to exclude these via
# the actions/cache path, e.g. "!~/.cache/bazel/*/*/external/" but that
# doesn't seem to work.
run: |
rm -rf $(bazel info repository_cache)
rm -rf ~/.cache/bazel/*/*/external/
shell: bash
bazel-test:
name: 'Bazel tests'
needs: bazel-build
runs-on: ubuntu-latest
steps:
- name: 'Install Java ${{ env.USE_JAVA_VERSION }}'
uses: actions/setup-java@v2
with:
distribution: '${{ env.USE_JAVA_DISTRIBUTION }}'
java-version: '${{ env.USE_JAVA_VERSION }}'
- name: 'Check out repository'
uses: actions/checkout@v2
- name: 'Cache local Maven repository'
uses: actions/cache@v2
with:
path: |
~/.m2/repository
!~/.m2/repository/com/google/dagger
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: 'Cache Bazel files'
uses: actions/cache@v2
with:
path: ~/.cache/bazel
# Note: we could use the same key as bazel-build, but we separate them
# so that bazel-build's cache is smaller (~200Mb vs ~900Mb) and faster
# to load than this cache since it's the bottleneck of all other steps
key: ${{ runner.os }}-bazel-test-${{ github.sha }}
restore-keys: |
${{ runner.os }}-bazel-test-
${{ runner.os }}-bazel-build-${{ github.sha }}
${{ runner.os }}-bazel-build-
- name: 'Cache Gradle files'
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: 'Run Bazel tests'
run: bazel test --test_output=errors //...
shell: bash
- name: 'Run Bazel examples'
run: cd examples/bazel; bazel test --test_output=errors //...
shell: bash
- name: 'Clean bazel cache'
# According to the documentation, we should be able to exclude these via
# the actions/cache path, e.g. "!~/.cache/bazel/*/*/external/" but that
# doesn't seem to work.
run: |
rm -rf $(bazel info repository_cache)
rm -rf ~/.cache/bazel/*/*/external/
shell: bash
artifact-java-local-tests:
name: 'Artifact Java local tests'
needs: bazel-build
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@v2
- name: 'Cache Gradle files'
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: 'Download local snapshot for tests'
uses: actions/download-artifact@v2
with:
name: local-snapshot
path: ~/.m2/repository/com/google/dagger
- name: 'Gradle Java local tests'
run: ./util/run-local-gradle-tests.sh
shell: bash
artifact-android-local-tests:
name: 'Artifact Android local tests (AGP ${{ matrix.agp }})'
needs: bazel-build
runs-on: ubuntu-latest
strategy:
matrix:
agp: ['4.1.0', '4.2.0', '7.0.0']
steps:
- name: 'Check out repository'
uses: actions/checkout@v2
- name: 'Cache Gradle files'
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: 'Download local snapshot for tests'
uses: actions/download-artifact@v2
with:
name: local-snapshot
path: ~/.m2/repository/com/google/dagger
- name: 'Gradle Android local tests (AGP ${{ matrix.agp }})'
run: ./util/run-local-gradle-android-tests.sh "${{ matrix.agp }}"
shell: bash
- name: 'Upload test reports (AGP ${{ matrix.agp }})'
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: tests-reports-agp-${{ matrix.agp }}
path: ${{ github.workspace }}/**/build/reports/tests/*
publish-artifacts:
name: 'Publish Artifact'
needs: [bazel-test, artifact-java-local-tests, artifact-android-local-tests]
runs-on: ubuntu-latest
steps:
- name: 'Install Java ${{ env.USE_JAVA_VERSION }}'
uses: actions/setup-java@v2
with:
distribution: '${{ env.USE_JAVA_DISTRIBUTION }}'
java-version: '${{ env.USE_JAVA_VERSION }}'
server-id: sonatype-nexus-staging
server-username: CI_DEPLOY_USERNAME
server-password: CI_DEPLOY_PASSWORD
gpg-private-key: ${{ secrets.CI_GPG_PRIVATE_KEY }}
gpg-passphrase: CI_GPG_PASSPHRASE
- name: 'Check out repository'
uses: actions/checkout@v2
- name: 'Cache local Maven repository'
uses: actions/cache@v2
with:
path: |
~/.m2/repository
!~/.m2/repository/com/google/dagger
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: 'Cache Bazel files'
uses: actions/cache@v2
with:
path: ~/.cache/bazel
key: ${{ runner.os }}-bazel-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-bazel-build-
- name: 'Cache Gradle files'
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Publish artifacts
run: |
util/deploy-all.sh \
"gpg:sign-and-deploy-file" \
"${{ env.DAGGER_RELEASE_VERSION }}" \
"-DrepositoryId=sonatype-nexus-staging" \
"-Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/"
shell: bash
env:
CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }}
CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }}
CI_GPG_PASSPHRASE: ${{ secrets.CI_GPG_PASSPHRASE }}
- name: 'Set git credentials'
run: |
git config --global user.email "dagger-dev+github@google.com"
git config --global user.name "Dagger Team"
shell: bash
- name: 'Publish tagged release'
run: util/publish-tagged-release.sh ${{ env.DAGGER_RELEASE_VERSION }}
shell: bash
- name: 'Publish tagged docs'
run: util/publish-tagged-docs.sh ${{ env.DAGGER_RELEASE_VERSION }}
shell: bash
- name: 'Clean bazel cache'
# According to the documentation, we should be able to exclude these via
# the actions/cache path, e.g. "!~/.cache/bazel/*/*/external/" but that
# doesn't seem to work.
run: |
rm -rf $(bazel info repository_cache)
rm -rf ~/.cache/bazel/*/*/external/
shell: bash
26 changes: 2 additions & 24 deletions util/deploy-to-maven-central.sh
Expand Up @@ -43,30 +43,8 @@ bash $(dirname $0)/deploy-all.sh \
# Note: we detach from head before making any sed changes to avoid commiting
# a particular version to master.
git checkout --detach

# Set the version string that is used as a tag in all of our libraries. If
# another repo depends on a versioned tag of Dagger, their java_library.tags
# should match the versioned release.
sed -i s/'${project.version}'/"${VERSION_NAME}"/g build_defs.bzl

# Note: We avoid commiting until after deploying in case deploying fails and
# we need to run the script again.
git commit -m "${VERSION_NAME} release" build_defs.bzl
git tag -a -m "Dagger ${VERSION_NAME}" dagger-"${VERSION_NAME}"
git push origin tag dagger-"${VERSION_NAME}"

bash $(dirname $0)/publish-tagged-release.sh $VERSION_NAME
# Switch back to the original HEAD
git checkout -

# Publish javadocs to gh-pages
bazel build //:user-docs.jar
git clone --quiet --branch gh-pages \
https://github.com/google/dagger gh-pages > /dev/null
cd gh-pages
unzip ../bazel-bin/user-docs.jar -d api/$VERSION_NAME
rm -rf api/$VERSION_NAME/META-INF/
git add api/$VERSION_NAME
git commit -m "$VERSION_NAME docs"
git push origin gh-pages
cd ..
rm -rf gh-pages
bash $(dirname $0)/publish-tagged-docs.sh $VERSION_NAME
33 changes: 33 additions & 0 deletions util/publish-tagged-docs.sh
@@ -0,0 +1,33 @@
#!/bin/bash

set -eux

if [ $# -lt 1 ]; then
echo "usage $0 <version-name>"
exit 1;
fi
readonly VERSION_NAME=$1
shift 1

if [[ ! "$VERSION_NAME" =~ ^2\. ]]; then
echo 'Version name must begin with "2."'
exit 2
fi

if [[ "$VERSION_NAME" =~ " " ]]; then
echo "Version name must not have any spaces"
exit 3
fi

# Publish javadocs to gh-pages
bazel build //:user-docs.jar
git clone --quiet --branch gh-pages \
https://github.com/google/dagger gh-pages > /dev/null
cd gh-pages
unzip ../bazel-bin/user-docs.jar -d api/$VERSION_NAME
rm -rf api/$VERSION_NAME/META-INF/
git add api/$VERSION_NAME
git commit -m "$VERSION_NAME docs"
git push origin gh-pages
cd ..
rm -rf gh-pages
31 changes: 31 additions & 0 deletions util/publish-tagged-release.sh
@@ -0,0 +1,31 @@
#!/bin/bash

set -eux

if [ $# -lt 1 ]; then
echo "usage $0 <version-name>"
exit 1;
fi
readonly VERSION_NAME=$1
shift 1

if [[ ! "$VERSION_NAME" =~ ^2\. ]]; then
echo 'Version name must begin with "2."'
exit 2
fi

if [[ "$VERSION_NAME" =~ " " ]]; then
echo "Version name must not have any spaces"
exit 3
fi

# Set the version string that is used as a tag in all of our libraries. If
# another repo depends on a versioned tag of Dagger, their java_library.tags
# should match the versioned release.
sed -i s/'${project.version}'/"${VERSION_NAME}"/g build_defs.bzl

# Note: We avoid commiting until after deploying in case deploying fails and
# we need to run the script again.
git commit -m "${VERSION_NAME} release" build_defs.bzl
git tag -a -m "Dagger ${VERSION_NAME}" dagger-"${VERSION_NAME}"
git push origin tag dagger-"${VERSION_NAME}"

0 comments on commit 8184387

Please sign in to comment.