Skip to content

Commit

Permalink
fix: test github script in release workflow (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd committed Jul 17, 2024
1 parent 054492a commit e5a8af9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
32 changes: 8 additions & 24 deletions .github/workflows/nightly-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ permissions:
contents: read

jobs:
test:
permissions:
packages: write
uses: ./.github/workflows/release-tests.yaml
# test:
# permissions:
# packages: write
# uses: ./.github/workflows/release-tests.yaml

push:
runs-on: ubuntu-latest
environment: release
needs: test
environment: release-nightly
# needs: test
permissions:
contents: write
steps:
Expand All @@ -38,24 +38,8 @@ jobs:
path: build/

- name: Create tag
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
# try to create a tag, if it already exists, update it
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/nightly',
sha: context.sha
}).catch(err => {
if (err.status !== 422) throw err;
github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/nightly',
sha: context.sha
});
})
run: |
./hack/create-nightly-tag.sh
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-e2e-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- "**.svg"
- "adr/**"
- "docs/**"
- "hack/**"
- "CODEOWNERS"
- "goreleaser*.y*ml"
- ".github/workflows/*release*.y*ml"
Expand Down
60 changes: 60 additions & 0 deletions hack/create-nightly-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env sh

# This script creates and/or updates a nightly tag for the uds-cli repo
# The nightly tag is created from the latest commit on the main branch

# get oid and repositoryId for GH API Graphql Mutation
oid=$(gh api graphql -f query='
{
repository(owner: "defenseunicorns", name: "uds-cli") {
id
ref(qualifiedName: "refs/heads/main") {
target {
... on Commit {
oid
}
}
}
}
}' | jq -r '.data.repository.ref.target.oid')

repositoryId=$(gh api graphql -f query='
{
repository(owner: "defenseunicorns", name: "uds-cli") {
id
}
}' | jq -r '.data.repository.id')


# get existing nightly tag and save to existingTag var
existingRefId=$(gh api graphql -f query='
{
repository(owner: "defenseunicorns", name: "uds-cli") {
ref(qualifiedName: "refs/tags/nightly") {
id
}
}
}' | jq -r '.data.repository.ref.id')

# remove any existing nightly tags
gh api graphql -f query='
mutation DeleteRef {
deleteRef(input:{refId:"'$existingRefId'"}) {
clientMutationId
}
}' --silent &&

echo "Existing nightly tag removed successfully"

# create a signed nightly tag
gh api graphql -f query='
mutation CreateRef {
createRef(input:{name:"refs/tags/nightly",oid:"'$oid'",repositoryId:"'$repositoryId'"}) {
ref {
id
name
}
}
}' --silent &&

echo "New nightly tag created successfully"

0 comments on commit e5a8af9

Please sign in to comment.