Skip to content

Commit

Permalink
refactor(ci): composite actions
Browse files Browse the repository at this point in the history
Signed-off-by: vados <[email protected]>
  • Loading branch information
t3hmrman committed Dec 10, 2023
1 parent b37dffb commit 4b4a209
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 178 deletions.
106 changes: 0 additions & 106 deletions .github/workflows/build-and-test.yaml

This file was deleted.

120 changes: 120 additions & 0 deletions .github/workflows/build-and-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: build-and-test
description: Build and test pg_idkit (meant to run inside pg_idkit/builder container)
inputs:
artifact-name:
type: string
description: |
Desired artifact name (will replace the natural name)
rust-container-version:
type: string
default: 1.73
description: |
Version of rust to use in the container
apt-cache-dir:
type: string
default: /var/cache/apt
cargo-home-dir:
type: string
default: /usr/local/cargo
cargo-target-dir:
type: string
default: /usr/local/build/target
sccache-dir:
type: string
default: /usr/local/sccache
cargo-build-rustc-wrapper:
type: string
default: /usr/local/cargo/bin/sccache
cargo-env-incremental:
type: string
default: "0"
cargo-env-profile:
type: string
default: ci
outputs: {}
runs:
using: "composite"
env:
CARGO_HOME: ${{ inputs.cargo-home-dir }}
CARGO_TARGET_DIR: ${{ inputs.cargo-target-dir }}
SCCACHE_DIR: ${{ inputs.sccache-dir }}
CARGO_BUILD_RUSTC_WRAPPER: ${{ inputs.cargo-build-rustc-wrapper }}
CARGO_INCREMENTAL: ${{ inputs.cargo-env-incrmental }}
CARGO_PROFILE: ${{ inputs.cargo-profile }}
steps:
# Checkout the repo
- uses: actions/checkout@v3

#########
# Cache #
#########

- name: Cache CARGO_HOME
uses: actions/cache@v3
continue-on-error: false
with:
path: |
${{ inputs.cargo-home-dir }}
key: pg_idkit-tests-rust-${{ inputs.rust-container-version }}-cargo-${{ runner.os }}

- name: Cache apt install
uses: actions/cache@v3
continue-on-error: false
with:
path: |
${{ inputs.apt-cache-dir }}
key: pg_idkit-tests-apt-cache-${{ inputs.rust-container-version }}-cargo-${{ runner.os }}

- name: Cache sccache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
${{ inputs.sccache-dir }}
key: pg_idkit-tests-sccache-${{ inputs.rust-container-version }}-cargo-${{ runner.os }}

###############
# Build/Tests #
###############

- name: Add idkit to group
run: |
chgrp -R idkit $HOME &&
chgrp -R idkit /__w/pg_idkit &&
chmod g+w -R /__w/pg_idkit
# Run cargo build
- name: Run cargo test
run: |
su idkit -c "cargo build"
# Run cargo check
- name: Run cargo check
run: |
su idkit -c "cargo check"
# Run cargo test
- name: Run cargo test
run: |
su idkit -c "cargo test"
#############
# Artifacts #
#############

# Run cargo test
- name: Build a package
id: package
if: ${{ github.event_name == 'workflow_call' }}
run: |
su idkit -c "just package"
tar -cvf pg_idkit-$(just print-version).zip $(just print-pkg-output-dir)
echo filename=pg_idkit-$(just print-version).zip >> $GITHUB_OUTPUT
# Upload artifact
- name: Upload artifact
if: ${{ github.event_name == 'workflow_call' }}
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifact-name || steps.package.outputs.filename }}
path: ${{ steps.package.outputs.filename }}
69 changes: 0 additions & 69 deletions .github/workflows/build-rpm.yaml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/build-rpm/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: build-rpm
description: Build an RPM for pg_idkit
inputs:
artifact-name:
type: string
description: |
Desired artifact name (will replace the natural name)
gh-runner:
type: string
default: ubuntu-latest
decription: |
GitHub runner to use
rpm-arch:
type: string
default: x86_64
decription: |
Architecture to use while building the RPM
pgrx-version:
type: string
default: pg15
decription: |
PGRX version (ex. 'pg15', 'pg16')
outputs:
random-number:
description: "Random number"
value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
using: "composite"
steps:
- uses: actions/checkout@v3

- uses: Swatinem/rust-cache@v2

- name: Cache default PGRX_HOME
uses: actions/cache@v3
continue-on-error: false
with:
path: |
/home/runner/.pgrx
key: pg_idkit-pkg-rpm-pgrx-${{ inputs.rpm-arch }}-${{ inputs.gh-runner }}

- name: Install Rust deps
uses: taiki-e/install-action@v2
with:
tool: cargo-binstall,cargo-get,just,cargo-generate-rpm,[email protected]

- name: Initialize cargo-pgrx
run: |
[[ -d /home/runner/.pgrx ]] || cargo pgrx init
- name: Build RPM
run: just package build-rpm

- name: Get RPM output path
id: rpm-output
run: |
echo path=$(just print-rpm-output-path) >> $GITHUB_OUTPUT
echo filename=$(just print-rpm-output-file-name) >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.rpm-output.outputs.filename }}
path: ${{ steps.rpm-output.outputs.path }}
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
echo value=$(just print-version) >> $GITHUB_OUTPUT
- name: Build the RPM (reuse workflow)
uses: ./.github/workflows/build-rpm.yaml@release-prep-v0.1.0
uses: ./.github/workflows/build-rpm.yaml
with:
artifact-name: pg_idkit-v${{ steps.version.outputs.value }}.rpm

Expand All @@ -42,7 +42,7 @@ jobs:
echo value=$(just print-version) >> $GITHUB_OUTPUT
- name: Build the package (reuse workflow)
uses: ./.github/workflows/build-and-test.yaml@release-prep-v0.1.0
uses: ./.github/workflows/build-and-test.yaml
with:
artifact-name: pg_idkit-v${{ steps.version.outputs.value }}.zip

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3

- name: Build & test the project
uses: ./.github/workflows/build-and-test.yaml
uses: ./.github/workflows/build-and-test
with:
rpm-arch: ${{ matrix.config.rpm.arch }}
pgrx-version: ${{ matrix.config.pgrx.version }}

0 comments on commit 4b4a209

Please sign in to comment.