Skip to content

Commit 87028fa

Browse files
authored
[REL-4161] Moving off Releaser and onto Github Actions (#511)
Converting Releaser scripts to a `release` GHA action. I'll leave the .ldreleaser stuff for now for reference, but probably makes sense to get rid of those once we're sure the GHA works well. <!-- ld-jira-link --> --- Related Jira issue: [REL-4161: Migrate ld-find-code-refs from Releaser to GHA](https://launchdarkly.atlassian.net/browse/REL-4161) <!-- end-ld-jira-link -->
1 parent 7a2f358 commit 87028fa

File tree

9 files changed

+370
-1
lines changed

9 files changed

+370
-1
lines changed

.github/workflows/release.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dryRun:
7+
description: Perform a dry-run only
8+
required: false
9+
type: boolean
10+
releaseVersion:
11+
description: Next release version
12+
required: true
13+
type: string
14+
changeLog:
15+
description: Pending changelog
16+
required: true
17+
type: string
18+
19+
jobs:
20+
release:
21+
permissions:
22+
id-token: 'write'
23+
runs-on: ubuntu-latest
24+
env:
25+
LD_RELEASE_VERSION: ${{ inputs.releaseVersion }}
26+
DRY_RUN: ${{ inputs.dryRun || 'false' }}
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
ARTIFACT_DIRECTORY: "/tmp/release-artifacts"
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
- uses: launchdarkly/gh-actions/actions/[email protected]
34+
name: Get secrets
35+
with:
36+
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
37+
ssm_parameter_pairs: '/global/services/docker/public/username = DOCKER_USERNAME, /global/services/docker/public/token = DOCKER_TOKEN, /production/common/releasing/circleci/orb-token= CIRCLECI_CLI_TOKEN, /production/common/releasing/bitbucket/username = BITBUCKET_USERNAME, /production/common/releasing/bitbucket/token = BITBUCKET_TOKEN'
38+
- name: setup access for find-code-references
39+
uses: launchdarkly/gh-actions/actions/ssh-key-by-repo@main
40+
with:
41+
repo_keys_map: |
42+
{
43+
"launchdarkly/find-code-references": ${{ toJSON(secrets.LAUNCHDARKLY_FIND_CODE_REFERENCES_DEPLOY_KEY) }}
44+
}
45+
- name: build
46+
run: |
47+
if [[ $LD_RELEASE_VERSION == v* ]]; then
48+
echo "Remove v prefix from version: $LD_RELEASE_VERSION"
49+
exit 1
50+
fi
51+
52+
make build
53+
- name: prepare release
54+
run: ./scripts/release/prepare-release.sh
55+
- name: publish
56+
run: |
57+
if [[ "$DRY_RUN" = true ]]; then
58+
./scripts/release/publish-dry-run.sh
59+
else
60+
./scripts/release/publish.sh
61+
fi
62+
- name: Commit changes and tag
63+
run: |
64+
./scripts/release/commit-and-tag.sh
65+
- name: Create Github release
66+
uses: ncipollo/[email protected]
67+
if: ${{ inputs.dryRun != 'true' }}
68+
with:
69+
token: ${{ secrets.GITHUB_TOKEN }}
70+
tag: v${{ inputs.releaseVersion }}
71+
body: ${{ inputs.changeLog }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ clean:
7272
rm -f build/package/github-actions/ld-find-code-refs-github-action
7373
rm -f build/package/bitbucket-pipelines/ld-find-code-refs-bitbucket-pipeline
7474

75-
RELEASE_CMD=curl -sL https://git.io/goreleaser | GOPATH=$(mktemp -d) VERSION=$(GORELEASER_VERSION) GITHUB_TOKEN=$(GITHUB_TOKEN) bash -s -- --clean --release-notes $(RELEASE_NOTES)
75+
RELEASE_CMD=curl -sL https://git.io/goreleaser | GOPATH=$(mktemp -d) VERSION=$(GORELEASER_VERSION) GITHUB_TOKEN=$(GITHUB_TOKEN) bash -s -- --clean --debug --release-notes $(RELEASE_NOTES)
7676

7777
publish:
7878
$(RELEASE_CMD)

scripts/release/commit-and-tag.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
RELEASE_TAG="v${LD_RELEASE_VERSION}"
6+
7+
echo "Changes staged for release $RELEASE_TAG:"
8+
git diff
9+
10+
if [[ "$DRY_RUN" == "true" ]]; then
11+
echo "Dry run mode: skipping commit, tag, and push"
12+
else
13+
if tag_exists; then
14+
echo "Tag $RELEASE_TAG already exists. Aborting."
15+
exit 1
16+
fi
17+
18+
git config user.name "LaunchDarklyReleaseBot"
19+
git config user.email "[email protected]"
20+
git add .
21+
git commit -m "Prepare release ${RELEASE_TAG}"
22+
git tag "${RELEASE_TAG}"
23+
git push origin HEAD
24+
git push origin "${RELEASE_TAG}"
25+
fi
26+

scripts/release/prepare-release.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
RELEASE_TAG="v${LD_RELEASE_VERSION}"
6+
7+
update_go() (
8+
sed -i "s/const Version =.*/const Version = \"${LD_RELEASE_VERSION}\"/g" internal/version/version.go
9+
)
10+
11+
update_orb() (
12+
sed -i "s#launchdarkly/ld-find-code-refs@.*#launchdarkly/ld-find-code-refs@${LD_RELEASE_VERSION}#g" build/package/circleci/orb.yml
13+
sed -i "s#- image: launchdarkly/ld-find-code-refs:.*#- image: launchdarkly/ld-find-code-refs:${LD_RELEASE_VERSION}#g" build/package/circleci/orb.yml
14+
)
15+
16+
update_gha() (
17+
sed -i "s#launchdarkly/find-code-references@v.*#launchdarkly/find-code-references@${RELEASE_TAG}#g" build/metadata/github-actions/README.md
18+
sed -i "s#launchdarkly/ld-find-code-refs-github-action:.*#launchdarkly/ld-find-code-refs-github-action:${LD_RELEASE_VERSION}#g" build/metadata/github-actions/Dockerfile
19+
)
20+
21+
update_bitbucket() (
22+
sed -i "s#- pipe: launchdarkly/ld-find-code-refs-pipe.*#- pipe: launchdarkly/ld-find-code-refs-pipe:${LD_RELEASE_VERSION}#g" build/metadata/bitbucket/README.md
23+
sed -i "s#image: launchdarkly/ld-find-code-refs-bitbucket-pipeline:.*#image: launchdarkly/ld-find-code-refs-bitbucket-pipeline:${LD_RELEASE_VERSION}#g" build/metadata/bitbucket/pipe.yml
24+
)
25+
26+
tag_exists() (
27+
git fetch --tags
28+
git rev-parse "${RELEASE_TAG}" >/dev/null 2>&1
29+
)
30+
31+
update_go
32+
update_orb
33+
update_gha
34+
update_bitbucket

scripts/release/publish-dry-run.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo ${DOCKER_TOKEN} | sudo docker login --username ${DOCKER_USERNAME} --password-stdin
6+
7+
sudo PATH=${PATH} GITHUB_TOKEN=${GITHUB_TOKEN} make products-for-release
8+
9+
mkdir -p ${ARTIFACT_DIRECTORY}
10+
11+
# Copy the Docker image that goreleaser just built into the artifacts - we only do
12+
# this in a dry run, because in a real release the image will be available from
13+
# DockerHub anyway so there's no point in attaching it to the release.
14+
BASE_CODEREFS=ld-find-code-refs
15+
GH_CODEREFS=ld-find-code-refs-github-action
16+
BB_CODEREFS=ld-find-code-refs-bitbucket-pipeline
17+
sudo docker save launchdarkly/${BASE_CODEREFS}:latest | gzip >${ARTIFACT_DIRECTORY}/${BASE_CODEREFS}.tar.gz
18+
sudo docker save launchdarkly/${GH_CODEREFS}:latest | gzip >${ARTIFACT_DIRECTORY}/${GH_CODEREFS}.tar.gz
19+
sudo docker save launchdarkly/${BB_CODEREFS}:latest | gzip >${ARTIFACT_DIRECTORY}/${BB_CODEREFS}.tar.gz
20+
21+
for script in $(dirname $0)/targets/*.sh; do
22+
source $script
23+
done
24+
25+
dry_run_bitbucket
26+
dry_run_gha
27+
dry_run_circleci

scripts/release/publish.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
sudo docker login --username ${DOCKER_USERNAME} --password-stdin ${DOCKER_TOKEN}
6+
7+
sudo PATH=${PATH} GITHUB_TOKEN=${GITHUB_TOKEN} make publish
8+
9+
# make bitbucket and github known hosts to push successfully
10+
mkdir –m700 ~/.ssh
11+
touch ~/.ssh/known_hosts
12+
chmod 644 ~/.ssh/known_hosts
13+
ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts
14+
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
15+
16+
for script in $(dirname $0)/targets/*.sh; do
17+
source $script
18+
done
19+
20+
publish_gha
21+
publish_circleci
22+
publish_bitbucket
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Run this in publish step after all version information have been updated.
4+
set -euo pipefail
5+
6+
setup_bitbucket() (
7+
rm -rf bitbucketMetadataUpdates
8+
mkdir -p bitbucketMetadataUpdates
9+
git clone "https://${BITBUCKET_USERNAME}:${BITBUCKET_TOKEN}@bitbucket.org/launchdarkly/ld-find-code-refs-pipe.git" bitbucketMetadataUpdates
10+
cp build/metadata/bitbucket/* bitbucketMetadataUpdates/
11+
cp CHANGELOG.md bitbucketMetadataUpdates/
12+
cd bitbucketMetadataUpdates
13+
git config user.email "[email protected]"
14+
git config user.name "LaunchDarklyReleaseBot"
15+
git add -u
16+
git commit -m "Release auto update version $LD_RELEASE_VERSION"
17+
git remote add bb-origin "https://${BITBUCKET_USERNAME}:${BITBUCKET_TOKEN}@bitbucket.org/launchdarkly/ld-find-code-refs-pipe.git"
18+
)
19+
20+
clean_up_bitbucket() (
21+
cd .. && rm -rf bitbucketMetadataUpdates
22+
)
23+
24+
publish_bitbucket() (
25+
setup_bitbucket
26+
cd bitbucketMetadataUpdates
27+
28+
if git ls-remote --tags origin "refs/tags/v$VERSION" | grep -q "v$VERSION"; then
29+
echo "Version exists; skipping publishing BitBucket Pipe"
30+
else
31+
echo "Live run: will publish pipe to bitbucket."
32+
git tag $LD_RELEASE_VERSION
33+
git push bb-origin master --tags
34+
fi
35+
36+
clean_up_bitbucket
37+
)
38+
39+
dry_run_bitbucket() (
40+
setup_bitbucket
41+
42+
echo "Dry run: will not publish pipe to bitbucket."
43+
cd bitbucketMetadataUpdates
44+
git push bb-origin master --tags --dry-run
45+
46+
clean_up_bitbucket
47+
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# Run this in publish step after all version information have been updated.
4+
set -euo pipefail
5+
6+
CIRCLECI_CLI_HOST="https://circleci.com"
7+
8+
install_circleci() (
9+
# Install the CircleCI CLI tool.
10+
# https://github.com/CircleCI-Public/circleci-cli
11+
# Dependencies: curl, cut
12+
# The version to install and the binary location can be passed in via VERSION and DESTDIR respectively.
13+
14+
# GitHub's URL for the latest release, will redirect.
15+
local GITHUB_BASE_URL="https://github.com/CircleCI-Public/circleci-cli"
16+
local LATEST_URL="${GITHUB_BASE_URL}/releases/latest/"
17+
local DESTDIR="${DESTDIR:-/usr/local/bin}"
18+
local VERSION=$(curl -sLI -o /dev/null -w '%{url_effective}' "$LATEST_URL" | cut -d "v" -f 2)
19+
20+
# Run the script in a temporary directory that we know is empty.
21+
local SCRATCH=$(mktemp -d || mktemp -d -t 'tmp')
22+
cd "$SCRATCH"
23+
24+
error() (
25+
echo "An error occured installing the tool."
26+
echo "The contents of the directory $SCRATCH have been left in place to help to debug the issue."
27+
)
28+
29+
trap error ERR
30+
31+
case "$(uname)" in
32+
Linux)
33+
OS='linux'
34+
;;
35+
Darwin)
36+
OS='darwin'
37+
;;
38+
*)
39+
echo "This operating system is not supported."
40+
exit 1
41+
;;
42+
esac
43+
44+
local RELEASE_URL="${GITHUB_BASE_URL}/releases/download/v${VERSION}/circleci-cli_${VERSION}_${OS}_amd64.tar.gz"
45+
46+
# Download & unpack the release tarball.
47+
curl -sL --retry 3 "${RELEASE_URL}" | tar zx --strip 1
48+
install circleci "$DESTDIR"
49+
command -v circleci
50+
51+
# Delete the working directory when the install was successful.
52+
rm -r "$SCRATCH"
53+
)
54+
55+
validate_circleci_orb_config() (
56+
circleci orb validate build/package/circleci/orb.yml || (echo "Unable to validate orb"; exit 1)
57+
)
58+
59+
publish_circleci() (
60+
install_circleci
61+
validate_circleci_orb_config
62+
63+
if circleci orb list | grep launchdarkly/ld-find-code-refs@$LD_RELEASE_VERSION; then
64+
echo "Version exists; skipping publishing CircleCI Orb"
65+
else
66+
echo "Live run: will publish orb to production circleci repo."
67+
circleci orb publish build/package/circleci/orb.yml launchdarkly/ld-find-code-refs@$LD_RELEASE_VERSION --token $CIRCLECI_CLI_TOKEN --host $CIRCLECI_CLI_HOST
68+
fi
69+
)
70+
71+
dry_run_circleci() (
72+
install_circleci
73+
validate_circleci_orb_config
74+
75+
echo "Dry run: will not publish orb to production. Will publish to circleci dev repo instead."
76+
circleci orb publish build/package/circleci/orb.yml launchdarkly/ld-find-code-refs@dev:$LD_RELEASE_VERSION --token $CIRCLECI_CLI_TOKEN --host $CIRCLECI_CLI_HOST
77+
)

scripts/release/targets/gha.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
# Run this in publish step after all version information have been updated.
4+
set -euo pipefail
5+
6+
RELEASE_TAG="v${LD_RELEASE_VERSION}"
7+
RELEASE_NOTES="$(make echo-release-notes)"
8+
9+
# All users of github action to reference major version tag
10+
VERSION_MAJOR="${LD_RELEASE_VERSION%%\.*}"
11+
RELEASE_TAG_MAJOR="v${VERSION_MAJOR}"
12+
13+
setup_gha() (
14+
# install gh cli so we can create a release later https://github.com/cli/cli/blob/trunk/docs/install_linux.md
15+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
16+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
17+
sudo apt update
18+
sudo apt install gh
19+
20+
gh auth setup-git
21+
22+
# clone checkout commit and push all metadata changes to gha repo
23+
mkdir -p githubActionsMetadataUpdates
24+
gh repo clone launchdarkly/find-code-references githubActionsMetadataUpdates
25+
cp build/metadata/github-actions/* githubActionsMetadataUpdates
26+
cd githubActionsMetadataUpdates
27+
git config user.email "[email protected]"
28+
git config user.name "LaunchDarklyReleaseBot"
29+
git branch -vv
30+
git add -u
31+
git commit -m "Release auto update version $LD_RELEASE_VERSION"
32+
pwd
33+
)
34+
35+
clean_up_gha() (
36+
cd .. && rm -rf githubActionsMetadataUpdates
37+
)
38+
39+
publish_gha() (
40+
setup_gha
41+
42+
if git ls-remote --tags origin "refs/tags/v$VERSION" | grep -q "v$VERSION"; then
43+
echo "Version exists; skipping publishing GHA"
44+
else
45+
echo "Live run: will publish action to github action marketplace."
46+
# tag the commit with the release version and create release
47+
git tag $RELEASE_TAG
48+
git push origin main --tags
49+
git tag -f $RELEASE_TAG_MAJOR
50+
git push -f origin $RELEASE_TAG_MAJOR
51+
gh release create $RELEASE_TAG --notes "$RELEASE_NOTES"
52+
fi
53+
54+
clean_up
55+
)
56+
57+
dry_run_gha() (
58+
setup_gha
59+
60+
echo "Dry run: will not publish action to github action marketplace."
61+
cd githubActionsMetadataUpdates
62+
git push origin main --tags --dry-run
63+
64+
clean_up_gha
65+
)

0 commit comments

Comments
 (0)