Skip to content

Commit

Permalink
ci: schedule with cron to auto release. (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Hanchin Hsieh <[email protected]>
  • Loading branch information
yuchanns authored Aug 2, 2024
1 parent 55a34a6 commit f2e8851
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 21 deletions.
40 changes: 40 additions & 0 deletions .github/scripts/setup_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const semver = require('semver')

const getLatestTag = async (github, owner, repo, tag_format) => {
const { status, data } = await github.rest.git.listMatchingRefs({
owner,
repo,
ref: `tags/${tag_format}`,
})
if (status != 200) {
throw new Error(`Failed to fetch tags for ${owner}/${repo}`)
}
const tags = data.map((ref) => {
const version = ref.ref.replace(`refs/tags/${tag_format}`, '')
return version
})
if (tags.length === 0) {
return '0.0.0'
}
max_version = tags.reduce((a, b) => semver.gt(a, b) ? a : b) ?? '0.0.0'
return max_version
}


module.exports = async ({ github }) => {
const bindingTag = await getLatestTag(github, 'apache', 'opendal', 'bindings/go/v')
const serviceTag = await getLatestTag(github, 'apache', 'opendal-go-services', 'v')

const opendalGoVersion = semver.gt(bindingTag, serviceTag) ? `v${bindingTag}` : ''
const opendalCoreVersion = `v${await getLatestTag(github, "apache", "opendal", "v")}`

console.log(`opendal_core_version=${opendalCoreVersion}`)
console.log(`opendal_go_version=${opendalGoVersion}`)

const fs = require('fs')
const output = process.env.GITHUB_OUTPUT

fs.appendFileSync(output, `opendal_core_version=${opendalCoreVersion}\n`)
fs.appendFileSync(output, `opendal_go_version=${opendalGoVersion}\n`)
}

68 changes: 47 additions & 21 deletions .github/workflows/build_artifacts.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
name: build_artifacts
on:
repository_dispatch:
types: [ build ]
workflow_dispatch:
inputs:
opendal_core_version:
description: "Version of Apache OpenDAL Core"
required: true
type: string
opendal_go_version:
description: "Version of Apache OpenDAL Go Binding"
required: false
type: string
schedule:
- cron: '*/5 * * * *'

jobs:
version_check:
runs-on: ubuntu-latest
outputs:
opendal_core_version: ${{ steps.set-version.outputs.opendal_core_version }}
opendal_go_version: ${{ steps.set-version.outputs.opendal_go_version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install Dependencies
run: npm install semver
- uses: actions/github-script@v7
id: set-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const script = require('.github/scripts/setup_version.js')
await script({github})
matrix:
needs: [ version_check ]
runs-on: ubuntu-latest
if: ${{ needs.version_check.outputs.opendal_go_version != '' }}
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
Expand All @@ -27,7 +42,7 @@ jobs:
echo "$MATRIX" | jq .
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
build:
needs: [ matrix ]
needs: [ version_check, matrix ]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -36,7 +51,7 @@ jobs:
- uses: actions/checkout@v4
with:
repository: "apache/opendal"
ref: ${{ inputs.opendal_core_version || github.event.client_payload.opendal_core_version }}
ref: ${{ needs.version_check.outputs.opendal_core_version }}
- uses: actions/checkout@v4
with:
path: "tools"
Expand Down Expand Up @@ -78,12 +93,12 @@ jobs:
zstd -22 ./target/$TARGET/release/libopendal_c.so -o ./libopendal_c.$TARGET.so.zst
- uses: actions/upload-artifact@v4
with:
name: "libopendal_c_${{ inputs.opendal_core_version || github.event.client_payload.opendal_core_version }}_${{ matrix.service }}_${{ matrix.build.target }}"
name: "libopendal_c_${{ needs.version_check.outputs.opendal_core_version }}_${{ matrix.service }}_${{ matrix.build.target }}"
if-no-files-found: "error"
path: "bindings/c/libopendal_c.${{ matrix.build.target }}.so.zst"
overwrite: "true"
generate:
needs: [ matrix, build ]
needs: [ version_check, matrix, build ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -92,34 +107,45 @@ jobs:
- name: Generate Template
env:
MATRIX: ${{ needs.matrix.outputs.matrix }}
VERSION: ${{ inputs.opendal_core_version || github.event.client_payload.opendal_core_version }}
VERSION: ${{ needs.version_check.outputs.opendal_core_version }}
working-directory: internal/generate
run: |
go run generate.go
- name: Auto Commit
env:
VERSION: ${{ inputs.opendal_core_version || github.event.client_payload.opendal_core_version }}
VERSION: ${{ needs.version_check.outputs.opendal_core_version }}
TAG: ${{ needs.version_check.outputs.opendal_go_version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "Github Actions"
git config --global user.email "[email protected]"
git add -A
git commit --allow-empty -m "Auto commit by GitHub Actions $VERSION"
git push -f --set-upstream origin main
- name: Auto Tag
if: ${{ needs.version_check.outputs.opendal_go_version != '' }}
env:
TAG: ${{ needs.version_check.outputs.opendal_go_version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# The tag is used for version_check only.
git tag $TAG
git push -f origin $TAG
tag:
needs: [ matrix, build, generate ]
needs: [ version_check, matrix, build, generate ]
runs-on: ubuntu-latest
if: ${{ needs.version_check.outputs.opendal_go_version != '' }}
strategy:
fail-fast: false
matrix:
service: ${{ fromJson(needs.matrix.outputs.matrix).service }}
steps:
- uses: actions/checkout@v4
- name: Auto Tag
if: ${{ inputs.opendal_go_version != '' || github.event.client_payload.opendal_go_version != '' }}
- name: Auto Service Tag
env:
SERVICE: ${{ matrix.service }}
VERSION: ${{ inputs.opendal_go_version || github.event.client_payload.opendal_go_version }}
VERSION: ${{ needs.version_check.outputs.opendal_go_version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
SERVICE=$(echo $SERVICE | tr '-' '_')
TAG="$SERVICE/$VERSION"
Expand Down

0 comments on commit f2e8851

Please sign in to comment.