-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
42 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 |
---|---|---|
|
@@ -2,53 +2,68 @@ name: release | |
|
||
on: | ||
push: | ||
branches: [ 'main' ] | ||
branches: ["main"] | ||
|
||
concurrency: server-release | ||
|
||
jobs: | ||
prepare: | ||
name: prepare | ||
outputs: | ||
version: ${{needs.prepare.outputs.version}} | ||
runs-on: "ubuntu-18.04" | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: "^1.17" | ||
- name: Calculate Next Release Version | ||
id: version | ||
run: | | ||
echo ${{ secrets.GITHUB_TOKEN }} > token | ||
gh auth login --with-token < token | ||
go install github.com/davidrjonas/semver-cli@latest | ||
commit=$(git log --format="%H" -n 1) | ||
last_pr=$(gh api -X GET search/issues -f q="repo:olegsu/bizbuzim is:closed is:pr sort:created-desc $commit" --jq '.items[0].number') | ||
if [[ $last_pr = "" ]]; then echo "No pull request found" && exit 0; fi; | ||
bump=$(gh pr view $last_pr --json labels --jq '.labels | map(select(.name | contains("release")) | .name) | .[0]' | sed s/release-//g) | ||
if ! [[ "$bump" =~ ^(minor|patch|major) ]]; then echo "Not a release commit" && exit 0; fi; | ||
echo $bump > bump.txt | ||
cat bump.txt | ||
current=$(gh release list | awk '{print $1}' | awk 'NR==1' | sed s/v//g) | ||
next_version=$(semver-cli inc $bump $current) | ||
echo "next_version is now $next_version" | ||
echo "::set-output name=version::$next_version" | ||
release: | ||
name: release | ||
runs-on: "ubuntu-18.04" | ||
needs: [prepare] | ||
if: needs.prepare.outputs.version | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: '^1.17' | ||
- name: Calculate Next Release Version | ||
run: | | ||
echo ${{ secrets.GITHUB_TOKEN }} > token | ||
gh auth login --with-token < token | ||
commit=$(git log --format="%H" -n 1) | ||
last_pr=$(gh api -X GET search/issues -f q="repo:olegsu/pull-requests-robot is:closed is:pr sort:created-desc $commit" --jq '.items[0].number') | ||
if [[ $last_pr = "" ]]; then echo "No pull request found" && exit 1; fi; | ||
bump=$(gh pr view $last_pr --json labels --jq '.labels | map(select(.name | contains("release")) | .name) | .[0]') | ||
if ! [[ "$bump" =~ ^(release-minor|release-patch|release-major) ]]; then echo "Not a release commit" && exit 1; fi; | ||
echo $bump > bump.txt | ||
current=$(gh release list | awk '{print $1}' | awk 'NR==1' | sed s/v//g) | ||
echo $current > version.txt | ||
- uses: olegsu/semver-action@v1 | ||
id: version | ||
with: | ||
version_file: "./version.txt" | ||
bump_file: "./bump.txt" | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- id: 'auth' | ||
name: 'Authenticate to Google Cloud' | ||
uses: 'google-github-actions/[email protected]' | ||
with: | ||
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' | ||
- name: Build | ||
run: docker build -t $(cat docker-repository.txt):${{ steps.version.outputs.version }} . | ||
- name: Push | ||
run: | | ||
gcloud auth configure-docker us-central1-docker.pkg.dev | ||
docker push $(cat docker-repository.txt):${{ steps.version.outputs.version }} | ||
- name: Update Cloud run | ||
run: gcloud run services update server --region us-central1 --image $(cat docker-repository.txt):${{ steps.version.outputs.version }} | ||
- name: Release | ||
run: gh release create v${{ steps.version.outputs.version }} | ||
|
||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: "^1.17" | ||
- name: Login To Github | ||
run: | | ||
echo ${{ secrets.GITHUB_TOKEN }} > token | ||
gh auth login --with-token < token | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- id: "auth" | ||
name: "Authenticate to Google Cloud" | ||
uses: "google-github-actions/[email protected]" | ||
with: | ||
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" | ||
- name: Build | ||
run: docker build -t $(cat docker-repository.txt):${{needs.prepare.outputs.version}} . | ||
- name: Push | ||
run: | | ||
gcloud auth configure-docker us-central1-docker.pkg.dev | ||
docker push $(cat docker-repository.txt):${{needs.prepare.outputs.version}} | ||
- name: Update Cloud run | ||
run: gcloud run services update server --region us-central1 --image $(cat docker-repository.txt):${{needs.prepare.outputs.version}} | ||
- name: Release | ||
run: gh release create v${{needs.prepare.outputs.version}} |