Skip to content

Commit

Permalink
build: Setup a release pipeline - bug fixes, optimizations and polish…
Browse files Browse the repository at this point in the history
…ing (#691)
  • Loading branch information
steve-todorov committed May 23, 2023
1 parent ea2b4d1 commit cc200cf
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ updates:
- package-ecosystem: "gradle"
directory: "/" # Location of package manifests
schedule:
interval: "daily"
interval: "weekly"
commit-message:
prefix: deps(upgrade)
26 changes: 21 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
name: Build and test
on:
# Build PRs
pull_request: ~
pull_request:
paths-ignore:
- 'docs/**'
- '*.md'
- '**/*.md'
- '.github/workflows/bump*.yaml'
- '.github/workflows/codeql*.yaml'
- '.github/workflows/command-*.yaml'
- '.github/workflows/deploy-tag.yaml'
- '.github/workflows/prepare-release.yaml'

# On push event
push:
# Build only changes pushed into the `master` branch.
Expand All @@ -13,12 +23,18 @@ on:
- 'docs/**'
- '*.md'
- '**/*.md'
- '.github/workflows/bump*.yaml'
- '.github/workflows/codeql*.yaml'
- '.github/workflows/command-*.yaml'
- '.github/workflows/deploy-tag.yaml'
- '.github/workflows/prepare-release.yaml'

workflow_dispatch:

# Currently you cannot use ${{ env.IS_FORK }} for some reason, which is why you might need to copy-paste some of these.
env:
REPOSITORY: ${{ github.repository }}
IS_FORK: ${{ github.repository != 'carlspring/s3fs-nio' }}
IS_FORK: ${{ github.repository != vars.CURRENT_REPO }}
IS_PR: ${{ github.event_name == 'pull_request' }}
EVENT_NAME: ${{ toJSON(github.event_name) }}
# format: username:branch
Expand All @@ -33,6 +49,8 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
java: [ 8, 11 ]
#os: [ ubuntu-latest ]
#java: [ 11 ]
steps:
- name: Show GitHub context
run: echo "$EVENT_NAME $REPOSITORY $PR_HEAD_LABEL $IS_PR $IS_FORK"
Expand Down Expand Up @@ -130,9 +148,7 @@ jobs:
# Publish snapshot only when on master branch, version is actually snapshot and from just one of the matrix jobs.
- name: Publish snapshot (only on master branch)
# TODO: Add this back before merge.
# ${{ github.ref_name == 'master' }} &&
if: ${{ fromJSON(steps.deploy_check.outputs.result).is_deployable == 'true' }}
if: ${{ github.ref_name == 'master' }} && ${{ fromJSON(steps.deploy_check.outputs.result).is_deployable == 'true' }}
env:
S3FS_PUBLISH_SONATYPE_USER: "${{ secrets.S3FS_PUBLISH_SONATYPE_USER }}"
S3FS_PUBLISH_SONATYPE_PASS: "${{ secrets.S3FS_PUBLISH_SONATYPE_PASS }}"
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/bump-snapshot-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ on:
description: Next snapshot version (i.e. 1.2.3, no SNAPSHOT suffix)

name: Bump snapshot version

env:
IS_FORK: ${{ github.repository != 'carlspring/s3fs-nio' }}
IS_ADMIN: ${{ github.triggering_actor == 'carlspring' || github.triggering_actor == 'steve-todorov' }}
run-name: Bump snapshot version to ${{ inputs.VERSION }}-SNAPSHOT

jobs:
bump-version:
runs-on: ubuntu-latest
if: |
${{ github.repository == 'carlspring/s3fs-nio' }} &&
${{ (github.triggering_actor == 'carlspring' || github.triggering_actor == 'steve-todorov') == true }}
github.repository == vars.CURRENT_REPO &&
contains('["carlspring", "steve-todorov"]', github.triggering_actor)
permissions:
contents: write
pull-requests: write
Expand Down Expand Up @@ -54,8 +51,8 @@ jobs:
- name: Bump version
run: |
cat <<< $(jq '."." = "${{ inputs.VERSION }}-SNAPSHOT"' .release-please-manifest.json) > .release-please-manifest.json
sed -i 's/version\ \= .*/version = "${{ inputs.VERSION }}-SNAPSHOT"/g' gradle.properties
sed -i 's/POM_VERSION: .*/POM_VERSION: "${{ inputs.VERSION }}-SNAPSHOT"/g' docs/mkdocs.yaml
sed -Ei 's/version([ ]*)\=.*/version=${{ inputs.VERSION }}-SNAPSHOT/g' gradle.properties
sed -Ei 's/POM_VERSION:.*/POM_VERSION: "${{ inputs.VERSION }}-SNAPSHOT"/g' docs/mkdocs.y*ml
- name: Create PR
uses: peter-evans/create-pull-request@v5
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,27 @@ name: "CodeQL"
on:
push:
branches: [ "master" ]
paths-ignore:
- 'docs/**'
- '*.md'
- '**/*.md'
- '.github/workflows/bump*.yaml'
- '.github/workflows/command-*.yaml'
- '.github/workflows/deploy-tag.yaml'
- '.github/workflows/prepare-release.yaml'
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
# schedule:
# - cron: '21 3 * * 4'
paths-ignore:
- 'docs/**'
- '*.md'
- '**/*.md'
- '.github/workflows/bump*.yaml'
- '.github/workflows/command-*.yaml'
- '.github/workflows/deploy-tag.yaml'
- '.github/workflows/prepare-release.yaml'

jobs:
analyze:
Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/command-deploy-pr-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
on:
repository_dispatch:
types: [ deploy-pr-command ]

name: command-deploy-pr
run-name: Deploying PR-${{ github.event.client_payload.github.payload.issue.number }}-SNAPSHOT@${{ github.event.client_payload.pull_request.head.sha }}

permissions:
contents: write
pull-requests: write
actions: write

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.pull_request.head.sha }}

- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: 11
distribution: "temurin"

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
# The Gradle wrapper's version (already the default, putting it here to clarity)
gradle-version: wrapper
# Removing unused files from Gradle User Home before saving to cache (i.e. older versions of gradle)
gradle-home-cache-cleanup: true
# Cache downloaded JDKs in addition to the default directories.
gradle-home-cache-includes: |
caches
notifications
jdks
- name: Build and deploy snapshot PR-${{ github.event.client_payload.github.payload.issue.number }}-SNAPSHOT
env:
S3FS_BUCKET_NAME: ${{ secrets.S3FS_BUCKET_NAME }}
S3FS_ACCESS_KEY: ${{ secrets.S3FS_ACCESS_KEY }}
S3FS_SECRET_KEY: ${{ secrets.S3FS_SECRET_KEY }}
S3FS_REGION: ${{ secrets.S3FS_REGION }}
S3FS_PROTOCOL: "https"
S3FS_PUBLISH_SONATYPE_USER: "${{ secrets.S3FS_PUBLISH_SONATYPE_USER }}"
S3FS_PUBLISH_SONATYPE_PASS: "${{ secrets.S3FS_PUBLISH_SONATYPE_PASS }}"
run: ./gradlew build publish --warn --stacktrace -Pversion=PR-${{ github.event.client_payload.github.payload.issue.number }}-SNAPSHOT

# Add reaction to the comment
- name: Add success reaction
uses: peter-evans/create-or-update-comment@v2
if: ${{ success() }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray

# Add comment (for historic reasons)
- name: Add success reaction
uses: peter-evans/create-or-update-comment@v2
if: ${{ success() }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
body: |
PR-${{ github.event.client_payload.github.payload.issue.number }}-SNAPSHOT@${{ github.event.client_payload.pull_request.head.sha }} was successfully deployed!
Check the [build logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Add failure response
uses: peter-evans/create-or-update-comment@v2
if: ${{ failure() }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: -1
body: |
> FAILURE: Action failed! Check the [logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
22 changes: 14 additions & 8 deletions .github/workflows/command-dispatcher.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: Slash Command Dispatch
name: command-dispatch
on:
issue_comment:
types: [created]
#permissions:
# pull-requests: write
# issues: write
# contents: read
# repository-projects: read
# actions: write
permissions: write-all
permissions:
contents: write
pull-requests: write
actions: write
#permissions: write-all
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
if: |
contains('["carlspring", "steve-todorov"]', github.triggering_actor) &&
github.event.issue.pull_request
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v3
Expand All @@ -29,6 +30,11 @@ jobs:
"permission": "write",
"issue_type": "pull-request"
},
{
"command": "deploy-pr",
"permission": "write",
"issue_type": "pull-request"
},
{
"command": "help",
"permission": "write",
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/command-help.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: command-help
run-name: command-help PR-${{ github.event.client_payload.github.payload.issue.number }}

on:
repository_dispatch:
types: [help-command]
permissions:
issues: write
pull-requests: write
contents: write
jobs:
help:
runs-on: ubuntu-latest
steps:
- name: Dump the client payload context
env:
PAYLOAD_CONTEXT: ${{ toJson(github.event.client_payload) }}
run: echo "$PAYLOAD_CONTEXT"
- name: Update comment
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Command | Description
> --- | ---
> /merge-snapshot | Squash and merge snapshot PR.
> /merge-release | Squash and merge release PR.
> /deploy-pr | Deploys the PR as a snapshot version (i.e. `org.carlspring.cloud.aws:s3fs-nio:PR-${{ github.event.client_payload.github.payload.issue.number }}-SNAPSHOT` using ref `${{ github.event.client_payload.pull_request.head.sha }}`)
reaction-type: hooray
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ on:
repository_dispatch:
types: [ merge-release-command ]

name: merge-release-command
name: command-merge-release
run-name: command-merge-release PR-${{ github.event.client_payload.github.payload.issue.number }}

permissions:
contents: write
Expand All @@ -11,11 +12,6 @@ permissions:

jobs:
merge-release:
if: |
${{ github.repository == 'carlspring/s3fs-nio' }} &&
${{ (github.triggering_actor == 'carlspring' || github.triggering_actor == 'steve-todorov') == true }} &&
${{ github.event.client_payload.slash_command.command == 'merge-release' }} &&
${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
Expand All @@ -25,15 +21,30 @@ jobs:
# The method mappings can be found here: https://github.com/octokit/plugin-rest-endpoint-methods.js/blob/main/src/generated/endpoints.ts
# Method parameters are available in the api docs: https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#merge-a-pull-request
script: |
const response = await github.rest.pulls.listCommits({
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: '${{ github.event.client_payload.github.payload.issue.number }}'
});
const prTitle = pr.data.title
const isRelease = prTitle.includes("Release v")
if(!isRelease) {
console.log("")
console.error("/merge-snapshot is supposed to be executed only on pull requests updating the version to snapshot!")
console.log("")
process.exit(1)
}
const listCommits = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: '${{ github.event.client_payload.github.payload.issue.number }}',
headers: { 'X-GitHub-Api-Version': '2022-11-28' }
});
//console.log(response.data);
//console.log(listCommits.data);
const commits = [...response.data].map(c => c.commit);
const commits = [...listCommits.data].map(c => c.commit);
//console.log("Commits: ", commits);
const split = commits[0].message.split('\n');
Expand All @@ -42,7 +53,8 @@ jobs:
split.shift()
let commit_message = (split.join('\n') + "\n\nCo-authored-by: " + commits[0].author.name + " <" + commits[0].author.email + ">").trim();
console.log("Squash title: " + commit_title);
console.log("Squash message: " + commit_message);
console.log("Squash message: \n" + commit_message + "\n/Squash message\n");
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down Expand Up @@ -79,10 +91,25 @@ jobs:
gh workflow run deploy-tag.yaml -f TAG=v${{ fromJSON(steps.release.outputs.result).version }}
# Add reaction to the comment
- name: Add reaction
- name: Add success response
uses: peter-evans/create-or-update-comment@v2
if: ${{ success() }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray
body: |
> Success: Action was successful! Check the [logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Add failure response
uses: peter-evans/create-or-update-comment@v2
if: ${{ failure() }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: -1
body: |
> FAILURE: Action failed! Check the [logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
Loading

0 comments on commit cc200cf

Please sign in to comment.