Skip to content

Commit 204a475

Browse files
committed
add github actions
1 parent 65e7b83 commit 204a475

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed

.github/workflows/codebuild-ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Pull Request Checks
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on pull request events but only for the "main" branch
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
permissions:
13+
id-token: write # This is required for requesting the JWT
14+
15+
jobs:
16+
run-tests:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Configure AWS Credentials
20+
uses: aws-actions/configure-aws-credentials@v4
21+
with:
22+
aws-region: us-east-1
23+
# The Amazon Resource Name (ARN) of the role to assume. Use the provided credentials to assume an IAM role and configure the Actions environment with the assumed role credentials rather than with the provided credentials.
24+
role-to-assume: ${{ secrets.AWS_CODE_BUILD_ROLE_ARN }} # optional
25+
audience: sts.amazonaws.com
26+
- name: Run CodeBuild
27+
uses: aws-actions/aws-codebuild-run-build@v1
28+
with:
29+
project-name: CodeEditorTesting
30+
source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}'
31+
32+

.github/workflows/release.yml

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
name: Automated Release
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on updates to the "main" branch which include a version tag
6+
push:
7+
tags:
8+
- '**' # Push events to every tag including hierarchical tags like v1.0/beta
9+
10+
# Allows you to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
13+
14+
# Defines permissions granted to the GITHUB_TOKEN for this workflow run.
15+
# 'contents: write' is needed for actions like softprops/action-gh-release to create GitHub releases
16+
# and for peter-evans/create-pull-request if it were to commit to the same repo
17+
18+
permissions:
19+
contents: write
20+
21+
22+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
23+
jobs:
24+
# This job checks if the pushed tag is a valid version tag (starts with 'v')
25+
check-tag:
26+
runs-on: ubuntu-latest
27+
steps:
28+
# This step performs the tag check
29+
- name: Check tag is version tag
30+
id: check # Assign an ID to this step to reference its outputs
31+
run: |
32+
# Check if the GitHub reference (github.ref) starts with 'refs/tags/v'
33+
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
34+
REF="${{ github.ref }}"
35+
VERSION="${REF##refs/tags/v}"
36+
echo "Tag starts with 'v'."
37+
echo "Version: ${VERSION}"
38+
echo "Continuing..."
39+
# Set the version as an output variable for other jobs/steps
40+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
41+
exit 0
42+
else
43+
echo "The tag doesn't start with 'v'. To release a new version, the tag must start with 'v'"
44+
exit 1
45+
fi
46+
outputs:
47+
version: ${{ steps.check.outputs.version }}
48+
49+
# This job builds the release tarball and publishes it to GitHub Releases
50+
release:
51+
# Specifies the environment for this job (if you have environments configured)
52+
environment: release
53+
# This job runs on the latest Ubuntu environment
54+
runs-on: ubuntu-latest
55+
needs: [check-tag]
56+
container:
57+
image: node:20
58+
steps:
59+
# Checks out the repository code at the specific tag that triggered the workflow
60+
- name: Checkout the main branch
61+
uses: actions/checkout@v4
62+
- name: Install Dependencies
63+
run: |
64+
apt-get update
65+
apt-get install -y build-essential g++ libx11-dev libxkbfile-dev libsecret-1-dev libkrb5-dev python-is-python3 quilt
66+
# Builds the tarball
67+
- name: Build Tarball
68+
id: build
69+
run: |
70+
# Configure git safe directory for operations within the workspace
71+
git config --global --add safe.directory /__w/sagemaker-code-editor/sagemaker-code-editor
72+
73+
# Run the install script to build the tarball, passing the version
74+
sh ./scripts/install.sh -t ${{ needs.check-tag.outputs.version }}
75+
76+
# Define the tarball name based on the version
77+
TARBALL_NAME="code-editor${{ needs.check-tag.outputs.version }}.tar.gz"
78+
# Set the tarball name as an output variable
79+
echo "tarball_name=${TARBALL_NAME}" >> $GITHUB_OUTPUT
80+
81+
# Calculate the SHA256 hash of the tarball
82+
SHA256_HASH=$(sha256sum ${TARBALL_NAME} | awk '{ print $1 }')
83+
# Set the SHA256 hash as an output variable
84+
echo "sha256_hash=${SHA256_HASH}" >> $GITHUB_OUTPUT
85+
# Publishes the release to GitHub Releases
86+
- name: Publish Release
87+
id: publish # Assign an ID to this step to reference its outputs
88+
uses: softprops/action-gh-release@v2.2.2 # Caution: Due to recent update of action-gh-release, it now requires node24. So here we still used the previous version v2.2.2
89+
with:
90+
# Name of the release (e.g., "Code Editor x.y.z")
91+
name: Code Editor ${{ needs.check-tag.outputs.version }}
92+
# Tag name for the release (e.g., "vx.y.z")
93+
tag_name: v${{ needs.check-tag.outputs.version }}
94+
# Files to upload as release assets
95+
files: |
96+
${{ steps.build.outputs.tarball_name }}
97+
# Define outputs for this job
98+
outputs:
99+
sha256_hash: ${{ steps.build.outputs.sha256_hash }}
100+
assets: ${{ steps.publish.outputs.assets }}
101+
102+
# This job updates the feedstock repository
103+
update-feedstock-files:
104+
runs-on: ubuntu-latest
105+
# This job depends on the successful completion of 'check-tag' and 'release' jobs
106+
needs: [check-tag, release]
107+
steps:
108+
# Clones the feedstock repository (your fork)
109+
- name: Clone the feedstock repository
110+
uses: actions/checkout@v4
111+
with:
112+
repository: 'harvenstar/sagemaker-code-editor-feedstock'
113+
ref: 'dev'
114+
token: ${{ secrets.PERSONAL_TOKEN }}
115+
116+
- name: Create and checkout dynamic update branch
117+
id: create_branch # Assign an ID to this step to reference its outputs
118+
run: |
119+
# Generate a unique branch name using the version (e.g., "auto-update-v1.2.0")
120+
# This prevents conflicts with pre-existing branches from previous runs.
121+
NEW_BRANCH_NAME="auto-update-v${{ needs.check-tag.outputs.version }}"
122+
123+
git checkout -b ${NEW_BRANCH_NAME}
124+
echo "Created and switched to new branch: ${NEW_BRANCH_NAME}"
125+
126+
# Output the new branch name for use in later steps (e.g., creating the PR)
127+
echo "branch_name=${NEW_BRANCH_NAME}" >> $GITHUB_OUTPUT
128+
129+
# Updates the meta.yaml file in the cloned feedstock repository
130+
# Updates the meta.yaml file in the cloned feedstock repository
131+
- name: Update meta.yaml
132+
run: |
133+
# Get the version from the 'check-tag' job's output
134+
VERSION=${{ needs.check-tag.outputs.version }}
135+
136+
sed -i "s/{% set version = \".*\" %}/{% set version = \"$VERSION\" %}/" recipe/meta.yaml
137+
138+
URL="${{ fromJSON(needs.release.outputs.assets)[0].browser_download_url }}"
139+
sed -i "s|url: .*\.tar\.gz|url: $URL|" recipe/meta.yaml
140+
141+
SHA256=${{ needs.release.outputs.sha256_hash }}
142+
sed -i "s|sha256: [0-9a-f]*|sha256: $SHA256|" recipe/meta.yaml
143+
144+
# Displays the differences in meta.yaml after modifications for verification
145+
- name: Show changes in meta.yaml
146+
run: git diff recipe/meta.yaml
147+
148+
# Commits the changes to meta.yaml and pushes them to the dynamic branch in your feedstock fork
149+
- name: Commit and push changes
150+
# This step commits the modified 'recipe/meta.yaml' file and pushes it to the remote feedstock repository.
151+
# - Git user name and email are configured for the commit.
152+
# - 'git add' stages the changes.
153+
# - 'git commit' creates a commit with a message including the new version.
154+
# ' || echo "No changes to commit." ' prevents the workflow from failing if there are no changes (e.g., if re-running on same version with no actual file change).
155+
# - The current local branch (which is the dynamic branch, e.g., 'auto-update-vX.Y.Z') is pushed to the 'origin' remote.
156+
# This creates the branch on the remote if it doesn't exist.
157+
run: |
158+
git config user.name "github-actions[bot]"
159+
git config user.email "github-actions[bot]@users.noreply.github.com"
160+
git add recipe/meta.yaml
161+
162+
# Check if there are changes to commit to avoid error if meta.yaml is already up-to-date
163+
if git diff --staged --quiet; then
164+
echo "No changes to commit."
165+
else
166+
git commit -m "Update recipe to v${{ needs.check-tag.outputs.version }}"
167+
fi
168+
169+
# Get the current branch name (should be the dynamic one created earlier)
170+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
171+
echo "Pushing changes to origin/${CURRENT_BRANCH}"
172+
# Push the dynamic branch to your feedstock fork (origin)
173+
# The '-u' flag sets the upstream branch for future pushes/pulls from this local branch.
174+
git push -u origin ${CURRENT_BRANCH}
175+
176+
177+
# labels: automated-update, bot
178+
# assignees: harvenstar
179+
# reviewers: harvenstar
180+

0 commit comments

Comments
 (0)