Skip to content

Commit 7a57cb6

Browse files
committed
ci: added GitHub workflows
1 parent da48ec5 commit 7a57cb6

File tree

3 files changed

+189
-0
lines changed

3 files changed

+189
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build and Deploy to GitHub Registry
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
workflow_dispatch:
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ophiosdev/codex-cli
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Check out the repo
19+
id: checkout
20+
uses: actions/checkout@v5
21+
22+
- name: Get the version
23+
id: get_version
24+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
25+
26+
- name: Validate Semver
27+
id: semver
28+
uses: matt-usurp/validate-semver@v2
29+
with:
30+
version: ${{ steps.get_version.outputs.VERSION }}
31+
32+
- name: Log in to the Container registry
33+
id: login_registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=semver,pattern={{version}}
47+
type=semver,pattern={{major}}.{{minor}}
48+
type=semver,pattern={{major}}
49+
type=sha
50+
type=raw,value=latest,enable={{is_default_branch}}
51+
labels: |
52+
org.opencontainers.image.maintainer=Ophios GmbH
53+
- name: Build and push Docker image
54+
id: build_and_push
55+
uses: docker/build-push-action@v6
56+
with:
57+
context: .
58+
push: true
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
build-args: |
62+
CODEX_CLI_VERSION=${{ steps.get_version.outputs.VERSION }}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Create Linked Tag from Upstream Repo
2+
3+
on:
4+
schedule:
5+
# Runs 4 times a day (every 6 hours)
6+
- cron: '0 */6 * * *'
7+
8+
# A simple manual trigger for testing.
9+
workflow_dispatch:
10+
11+
permissions:
12+
# 'contents: write' is required to push tags to the repository.
13+
contents: write
14+
15+
jobs:
16+
sync-tag:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Get latest stable release from public upstream repo
21+
id: get_release_b
22+
uses: pozetroninc/github-action-get-latest-release@master
23+
with:
24+
# Reads the UPSTREAM_REPO variable from your repository settings.
25+
# This variable is REQUIRED for the workflow to function.
26+
repository: ${{ vars.UPSTREAM_REPO }}
27+
excludes: prerelease, draft
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Validate Release Tag Format
31+
id: validate_tag
32+
env:
33+
# Use the repo variable for the regex if it exists, otherwise use the default.
34+
VERSION_REGEX: ${{ vars.VERSION_REGEX || '^v?[0-9]+\.[0-9]+\.[0-9]+$' }}
35+
run: |
36+
TAG_NAME="${{ steps.get_release_b.outputs.release }}"
37+
38+
echo "Validating release tag format for latest release from upstream repository: $TAG_NAME"
39+
if [[ -z "$TAG_NAME" ]]; then
40+
echo "No valid release found from upstream repository. Exiting."
41+
echo "is_valid=false" >> "$GITHUB_OUTPUT"
42+
exit 0
43+
fi
44+
45+
if [[ "$TAG_NAME" =~ $VERSION_REGEX ]]; then
46+
echo "Tag '$TAG_NAME' matches the required format."
47+
echo "is_valid=true" >> "$GITHUB_OUTPUT"
48+
else
49+
echo "Tag '$TAG_NAME' does not match the required format. Ignoring."
50+
echo "is_valid=false" >> "$GITHUB_OUTPUT"
51+
fi
52+
53+
- name: Generate GitHub App token
54+
id: app_token
55+
uses: actions/create-github-app-token@v2
56+
with:
57+
app-id: ${{ secrets.WORKFLOW_APP_ID }}
58+
private-key: ${{ secrets.WORKFLOW_APP_PRIVATE_KEY }}
59+
60+
- name: Checkout repository code
61+
# We need to check out the code to be able to check for existing tags and push new ones.
62+
if: steps.validate_tag.outputs.is_valid == 'true'
63+
uses: actions/checkout@v5
64+
with:
65+
fetch-depth: 0
66+
fetch-tags: true
67+
token: ${{ steps.app_token.outputs.token }}
68+
69+
- name: Check if tag already exists locally
70+
id: check_tag
71+
if: steps.validate_tag.outputs.is_valid == 'true'
72+
env:
73+
RELEASE_TAG: ${{ steps.get_release_b.outputs.release }}
74+
run: |
75+
if git tag --list | grep -q "^${RELEASE_TAG}$"; then
76+
echo "Tag '$RELEASE_TAG' already exists. No action needed."
77+
echo "create_tag=false" >> "$GITHUB_OUTPUT"
78+
else
79+
echo "New valid tag '$RELEASE_TAG' detected!"
80+
echo "create_tag=true" >> "$GITHUB_OUTPUT"
81+
fi
82+
83+
- name: Create and push new tag
84+
# This step only runs if the tag is valid AND new.
85+
if: steps.check_tag.outputs.create_tag == 'true'
86+
env:
87+
RELEASE_TAG: ${{ steps.get_release_b.outputs.release }}
88+
run: |
89+
RELEASE_TAG="v${RELEASE_TAG#v}" # Ensure the tag starts with 'v'
90+
91+
echo "Creating tag: $RELEASE_TAG"
92+
git tag "$RELEASE_TAG"
93+
94+
echo "Pushing tag to remote..."
95+
git push origin "$RELEASE_TAG"
96+
97+
echo "Successfully created and pushed tag '$RELEASE_TAG'."

.github/workflows/pr-checks.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: Pull Request validation
3+
4+
on:
5+
- pull_request
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
id: checkout
13+
uses: actions/checkout@v5
14+
15+
- name: Set up Python
16+
id: setup-python
17+
uses: actions/setup-python@v5
18+
19+
- name: Run pre-commit checks
20+
id: pre-commit
21+
uses: cloudposse/github-action-pre-commit@v4.0.0
22+
23+
- name: Build Docker image if Dockerfile changed
24+
run: |
25+
if git diff --name-only origin/${{ github.base_ref }} | grep -q '^Dockerfile$'; then
26+
echo "Dockerfile changed — building image..."
27+
docker build -t codex-cli-pr:latest .
28+
else
29+
echo "Dockerfile not changed — skipping build."
30+
fi

0 commit comments

Comments
 (0)