Skip to content

Commit

Permalink
Merge pull request #36 from bcgov-nr/feat/buildRelease
Browse files Browse the repository at this point in the history
feat: clean commit for build-release changes
  • Loading branch information
GraceRuan authored Mar 15, 2024
2 parents 2c3f97c + 5d2c1f6 commit 66a9a59
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 159 deletions.
13 changes: 2 additions & 11 deletions generators/gh-maven-build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export default class extends Generator {
// Generate GitHub workflows and NR Broker intention files
writing() {
this.fs.copyTpl(
this.templatePath('build.yaml'),
this.destinationPath('.github/workflows/build.yaml'),
this.templatePath('build-release.yaml'),
this.destinationPath('.github/workflows/build-release.yaml'),
{
projectName: this.props.projectName,
serviceName: this.props.serviceName,
Expand All @@ -137,15 +137,6 @@ export default class extends Generator {
this.templatePath('build-intention.sh'),
this.destinationPath('.github/workflows/build-intention.sh'),
);
this.fs.copyTpl(
this.templatePath('release.yaml'),
this.destinationPath('.github/workflows/release.yaml'),
{
projectName: this.props.projectName,
serviceName: this.props.serviceName,
pomRoot: this.props.pomRoot,
},
);
if (this.props.deployOnPrem) {
this.fs.copyTpl(
this.templatePath('deploy.yaml'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
name: Build
name: Build and release

on:
push:
tags:
- 'v*'
pull_request:
branches:
- main
workflow_call:
outputs:
branch:
value: ${{ jobs.build.outputs.branch }}
project_version:
value: ${{ jobs.build.outputs.project_version }}
intention_id:
value: ${{ jobs.build.outputs.intention_id }}
workflow_dispatch:

concurrency:
Expand All @@ -25,26 +20,29 @@ env:
SERVICE_NAME: <%= serviceName %>

jobs:
<% if (unitTestsPath) { -%>
<% if (unitTestsPath) { -%>
test:
name: Test
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
uses: <%= unitTestsPath %>
<% } -%>
build:
name: Build
build-release:
name: Build and release
runs-on: ubuntu-latest
<% if (unitTestsPath) { -%>
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
needs: test
<% } -%>
permissions:
contents: read
packages: write
outputs:
branch: ${{ steps.set-branch.outputs.branch }}
project_version: ${{ steps.set-build-output-parameters.outputs.project_version }}
intention_id: ${{ steps.set-intention-id.outputs.intention_id }}
branch: $${{ steps.set-branch.outputs.branch }}
steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
Expand All @@ -56,19 +54,30 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Set branch
id: set-branch
id: set-branch
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
run: |
if [[ ${{ startsWith(github.ref, 'refs/heads/') }} = true ]]; then
echo "branch=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
if [[ ${{ startsWith(github.ref, 'refs/pull/') }} = true ]]; then
echo "branch=${{ github.head_ref }}" >> "$GITHUB_OUTPUT"
fi
- name: Update pom.xml
id: update-repo
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: |
TAG=${{ github.ref_name }}
VERSION=${TAG#v}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
mvn versions:set -DnewVersion=${VERSION} --file <%= pomRoot %>pom.xml
- name: Set build output parameters
id: set-build-output-parameters
run: |
echo "project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout --file <%= pomRoot %>pom.xml)" >> $GITHUB_OUTPUT
echo "artifact_id=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout --file <%= pomRoot %>pom.xml)" >> $GITHUB_OUTPUT
echo "package_type=$(mvn help:evaluate -Dexpression=project.packaging -q -DforceStdout --file <%= pomRoot %>pom.xml)" >> $GITHUB_OUTPUT
echo "git_commit=$(git rev-parse --verify HEAD)" >> $GITHUB_OUTPUT
- name: Build intention
run: sh ./.github/workflows/build-intention.sh
Expand All @@ -93,7 +102,32 @@ jobs:
echo "intention_id=${INTENTION_ID}" >> $GITHUB_OUTPUT
env:
INTENTION_ID: ${{ env.INTENTION_ID }}
- name: Publish to OpenShift Artifactory
- name: Publish artifact
id: publish-artifact
<% if (gitHubPackages) { -%>
run: |
ARTIFACT_NAME="${ARTIFACT_ID}-${PROJECT_VERSION}.${PACKAGE_TYPE}"
mvn --batch-mode -Dmaven.test.skip=true -Pgithub deploy --file <%= pomRoot %>pom.xml
echo "artifact_sha256=$(sha256sum target/${ARTIFACT_NAME} | awk '{ print $1 }')" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PROJECT_VERSION: ${{ steps.set-build-output-parameters.outputs.project_version }}
ARTIFACT_ID: ${{ steps.set-build-output-parameters.outputs.artifact_id }}
PACKAGE_TYPE: ${{ steps.set-build-output-parameters.outputs.package_type }}
- name: Send build info
run: |
ARTIFACT_NAME="${ARTIFACT_ID}-${PROJECT_VERSION}.${PACKAGE_TYPE}"
curl -s POST ${{ env.BROKER_URL }}/v1/intention/action/artifact \
-H 'Content-Type: application/json' \
-H 'X-Broker-Token: '"${BUILD_TOKEN}"'' \
-d '{"checksum": "sha256:'${ARTIFACT_SHA256}'", "name": "'${ARTIFACT_NAME}'", "type": "'${PACKAGE_TYPE}'" }'
env:
ARTIFACT_SHA256: ${{ steps.publish-artifact.outputs.artifact_sha256 }}
ARTIFACT_ID: ${{ steps.set-build-output-parameters.outputs.artifact_id }}
PROJECT_VERSION: ${{ steps.set-build-output-parameters.outputs.project_version }}
PACKAGE_TYPE: ${{ steps.set-build-output-parameters.outputs.package_type }}
BUILD_TOKEN: ${{ env.ACTION_TOKEN_BUILD }}
<% } else { -%>
run: mvn --batch-mode -Dmaven.test.skip=true -Partifactory deploy --file <%= pomRoot %>pom.xml
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
Expand All @@ -104,7 +138,7 @@ jobs:
id: set-build-info
run: |
BUILD_INFO=$(curl -s -u ${{ secrets.ARTIFACTORY_USERNAME }}:${{ secrets.ARTIFACTORY_PASSWORD }} \
https://artifacts.developer.gov.bc.ca/artifactory/api/build/${{ env.ARTIFACT_ID }}/${{ github.run_number }}?project=cc20)
https://artifacts.developer.gov.bc.ca/artifactory/api/build/${{ env.ARTIFACT_ID }}/${{ github.run_number }}?project=<%= artifactoryProject %>)
echo "vcs_revision=$(echo ${BUILD_INFO} | jq -r '.buildInfo.vcs[0].revision')" >> $GITHUB_OUTPUT
echo "vcs_message=$(echo ${BUILD_INFO} | jq -r '.buildInfo.vcs[0].message')" >> $GITHUB_OUTPUT
echo "vcs_branch=$(echo ${BUILD_INFO} | jq -r '.buildInfo.vcs[0].branch')" >> $GITHUB_OUTPUT
Expand All @@ -127,27 +161,9 @@ jobs:
ARTIFACT_NAME: ${{ steps.set-build-info.outputs.artifact_name }}
ARTIFACT_TYPE: ${{ steps.set-build-info.outputs.artifact_type }}
BUILD_TOKEN: ${{ env.ACTION_TOKEN_BUILD }}
<% } -%>
- name: Close intention
uses: bcgov-nr/action-broker-intention-close@v1
with:
intention_token: ${{ env.INTENTION_TOKEN }}
<% if (gitHubPackages) { -%>
ghcr:
name: GHCR
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Java for publishing to GitHub Packages
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Publish to GitHub Packages
run: mvn --batch-mode -Dmaven.test.skip=true -Pgithub deploy --file <%= pomRoot %>pom.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
<% } %>

111 changes: 0 additions & 111 deletions generators/gh-maven-build/templates/release.yaml

This file was deleted.

0 comments on commit 66a9a59

Please sign in to comment.