-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ci: delete branch snapshot * ci: increase expiration time for oracle in upgrade-assure
- Loading branch information
1 parent
974dc2b
commit 4c3c314
Showing
5 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Delete Snapshot on Branch Deletion | ||
|
||
on: | ||
delete: | ||
branches: | ||
- "**" | ||
|
||
jobs: | ||
delete-snapshot: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.21" | ||
|
||
- name: Cache delete-snapshot binary | ||
id: cache-delete-snapshot | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
./build | ||
key: ${{ runner.os }}-delete-snapshot-${{ hashFiles('cmd/delete-snapshot/*.go') }} | ||
|
||
- name: Build delete-snapshot binary | ||
if: steps.cache-delete-snapshot.outputs.cache-hit != 'true' | ||
run: | | ||
make build-delete-snapshot | ||
- name: Run delete-snapshot | ||
env: | ||
R2_ACCESS_KEY: ${{ secrets.R2_ACCESS_KEY }} | ||
R2_SECRET_KEY: ${{ secrets.R2_SECRET_KEY }} | ||
R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }} | ||
R2_BUCKET_NAME: ${{ secrets.R2_BUCKET_NAME }} | ||
run: | | ||
SANITIZED_HEAD_REF=${{ github.head_ref || github.ref }} | ||
SANITIZED_HEAD_REF=$(echo "$SANITIZED_HEAD_REF" | sed 's|refs/heads/||; s|/|_|g') | ||
./build/delete_snapshot "$SANITIZED_HEAD_REF" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/credentials" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
fmt.Println("Usage: <executable> <branch name>") | ||
os.Exit(1) | ||
} | ||
|
||
// Fetch credentials and configuration from environment variables | ||
accessKey := os.Getenv("R2_ACCESS_KEY") | ||
secretKey := os.Getenv("R2_SECRET_KEY") | ||
s3URL := os.Getenv("R2_ENDPOINT") | ||
bucketName := os.Getenv("R2_BUCKET_NAME") | ||
branchName := os.Args[1] | ||
|
||
// Ensure all required environment variables are set | ||
if accessKey == "" || secretKey == "" || s3URL == "" || bucketName == "" { | ||
fmt.Println("Please set R2_ACCESS_KEY, R2_SECRET_KEY, R2_ENDPOINT, and R2_BUCKET_NAME environment variables") | ||
os.Exit(1) | ||
} | ||
|
||
// Load AWS configuration with credentials | ||
cfg, err := config.LoadDefaultConfig( | ||
context.TODO(), | ||
config.WithCredentialsProvider( | ||
credentials.NewStaticCredentialsProvider(accessKey, secretKey, ""), | ||
), | ||
config.WithRegion("ENAM"), // Ensure this region is appropriate or set it via environment variable if needed | ||
config.WithEndpointResolverWithOptions( | ||
aws.EndpointResolverWithOptionsFunc( | ||
func(service, region string, options ...interface{}) (aws.Endpoint, error) { | ||
return aws.Endpoint{ | ||
URL: s3URL, | ||
}, nil | ||
}, | ||
), | ||
), | ||
) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to load configuration, %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Create an S3 client | ||
client := s3.NewFromConfig(cfg) | ||
|
||
// Replace '/' with '_' in the branch name | ||
safeBranchName := strings.ReplaceAll(branchName, "/", "_") | ||
|
||
// Construct the key for the snapshot file | ||
key := fmt.Sprintf("elys-snapshot-%s.tar.lz4", safeBranchName) | ||
|
||
// Delete the file | ||
_, err = client.DeleteObject(context.TODO(), &s3.DeleteObjectInput{ | ||
Bucket: &bucketName, | ||
Key: &key, | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to delete file %q from bucket %q, %v", key, bucketName, err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("Successfully deleted %q from %q\n", key, bucketName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters