Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(*): update markdown file #24

Merged
merged 39 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f4d771f
fix(*): update markdown file
HoseaCodes May 24, 2024
c251728
fix(*): remove unused packages
HoseaCodes May 25, 2024
476dd14
fix(*): update read time
HoseaCodes May 25, 2024
0600b75
feat(article): add linkedin posting
HoseaCodes May 26, 2024
bd2930e
fix(*): update sticky footer
HoseaCodes May 27, 2024
2d17b3f
fix(*): update env
HoseaCodes May 27, 2024
c803693
fix(*): update env
HoseaCodes May 27, 2024
fcc205a
fix(*): update pipeline
HoseaCodes May 27, 2024
90648dd
fix(*): update pipeline
HoseaCodes May 27, 2024
b83a2d8
fix(*): test tag in pipeline
HoseaCodes May 27, 2024
6cb7be4
fix(*): test tag in pipeline
HoseaCodes May 27, 2024
f47bcff
fix(*): test tag in pipeline
HoseaCodes May 27, 2024
15eae51
fix(*): test tag in pipeline
HoseaCodes May 27, 2024
e785257
fix(*): update tag in pipeline
HoseaCodes May 27, 2024
c564b8e
fix(*): update tag in pipeline
HoseaCodes May 27, 2024
5c88417
fix(*): update tag in pipeline
HoseaCodes May 27, 2024
7779484
fix(*): update tag in pipeline
HoseaCodes May 27, 2024
908f097
fix(*): update tag in pipeline
HoseaCodes May 27, 2024
a4ec7a1
fix(*): update tag in pipeline
HoseaCodes May 27, 2024
b87a0e7
fix(*): update build in pipeline
HoseaCodes May 27, 2024
66690d8
fix(*): update build in pipeline
HoseaCodes May 27, 2024
77d59ba
fix(*): update build in pipeline
HoseaCodes May 27, 2024
949923c
fix(*): update build in pipeline
HoseaCodes May 27, 2024
f13a124
fix(*): update build in pipeline
HoseaCodes May 27, 2024
427b147
fix(*): update build in pipeline
HoseaCodes May 27, 2024
509475e
fix(*): update build in pipeline
HoseaCodes May 27, 2024
e294b27
fix(*): update build in pipeline
HoseaCodes May 27, 2024
c06a808
fix(*): update build in pipeline
HoseaCodes May 27, 2024
4069ccb
fix(*): update build in pipeline
HoseaCodes May 27, 2024
0b09cf0
fix(*): update build in pipeline
HoseaCodes May 27, 2024
7aa3042
fix(*): update build in pipeline
HoseaCodes May 27, 2024
a9c39de
fix(*): update build in pipeline
HoseaCodes May 27, 2024
64c70df
fix(*): update build in pipeline
HoseaCodes May 27, 2024
94ac40c
fix(*): update build in pipeline
HoseaCodes May 27, 2024
994bf2f
fix(*): update build in pipeline
HoseaCodes May 27, 2024
6a7ee23
fix(*): update release tag in pipeline
HoseaCodes May 27, 2024
0cf4d53
fix(*): update release tag in pipeline
HoseaCodes May 27, 2024
f2593f8
fix(*): update remove unused code
HoseaCodes May 27, 2024
5411999
fix(*): update master pipeline
HoseaCodes May 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
push:
branches:
- main
tags:
- v*
jobs:
static-scan:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -58,6 +60,8 @@ jobs:
build:
needs: [static-scan, dependency-scan, lint]
runs-on: ubuntu-latest
outputs:
build_path: ${{ steps.archive_build.outputs.build_path }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
Expand All @@ -67,10 +71,45 @@ jobs:
node-version: '20'
- name: Install Dependencies
run: npm install --legacy-peer-deps
- name: Deploy to Heroku
- name: Build project
run: |
export SKIP_PREFLIGHT_CHECK=true
npm run build
- name: Archive build output
id: archive_build
run: |
git remote add heroku https://git.heroku.com/hoseacodes-dev.git
git push heroku main
tar -czf build.tar.gz build/
echo "::set-output name=build_path::build.tar.gz"
- name: Create conventional changelog action
id: changelog
uses: TriPSs/conventional-changelog-action@latest
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
tag-prefix: "dev.v"
git-push: false
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.changelog.outputs.tag }}
release_name: Release ${{ steps.changelog.outputs.tag }}
body: ${{steps.changelog.outputs.clean_changelog}}
draft: false
prerelease: false
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build.tar.gz
asset_name: build.tar.gz
asset_content_type: application/gzip
- name: Deploy to Heroku
uses: akhileshns/[email protected]
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: hoseacodes-dev
heroku_email: "[email protected]"
90 changes: 89 additions & 1 deletion .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,92 @@ jobs:
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
command: monitor
build:
needs: [security]
runs-on: ubuntu-latest
outputs:
build_path: ${{ steps.archive_build.outputs.build_path }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install Dependencies
run: npm install --legacy-peer-deps
- name: Build project
run: |
export SKIP_PREFLIGHT_CHECK=true
npm run build
- name: Archive build output
id: archive_build
run: |
tar -czf build.tar.gz build/
echo "::set-output name=build_path::build.tar.gz"
- name: Create conventional changelog action
id: changelog
uses: TriPSs/conventional-changelog-action@latest
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
tag-prefix: "dev.v"
git-push: false
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.changelog.outputs.tag }}
release_name: Release ${{ steps.changelog.outputs.tag }}
body: ${{steps.changelog.outputs.clean_changelog}}
draft: false
prerelease: false
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build.tar.gz
asset_name: build.tar.gz
asset_content_type: application/gzip
- name: Deploy to Heroku
uses: akhileshns/[email protected]
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: hoseacodes-dev
heroku_email: "[email protected]"
release:
needs: [build]
name: Release pushed tag
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # required for github-action-get-previous-tag
- name: Get previous tag
id: previoustag
uses: 'WyriHaximus/github-action-get-previous-tag@v1'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get next minor version
id: semver
uses: 'WyriHaximus/github-action-next-semvers@v1'
with:
version: ${{ steps.previoustag.outputs.tag }}
- name: Create release
id: create_release_id
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
gh release create "$tag ${{ steps.semver.outputs.patch }}" \
--repo="$GITHUB_REPOSITORY" \
--title="${GITHUB_REPOSITORY#*/} ${tag#v}" \
--generate-notes
with:
tag_name: ${{ steps.semver.outputs.patch }}
release_name: Release ${{ steps.semver.outputs.patch }}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ See [wiki](https://github.com/HoseaCodes/Blog/wiki/Backend) for details.

## Dev Ops

### Pipelines

| Job Name | Use Case |
| ----------------------------------------------------- | ----------- |
| Static-Scan | Static application security testing (SAST) or static code analysis, analyzes source code to find security vulnerabilities that make the organization's applications susceptible to attack. |
| Dependency-Scan | Dependency scanning generates an alert for any open-source component, direct or transitive, found to be vulnerable that the code depends upon. |
| Lint-Scan | Lint scans source code for errors and potential issues that could lead to bugs, vulnerabilities, and other problems. |
| Build | Build and deploying the project. |

See [wiki](https://github.com/HoseaCodes/Blog/wiki/Dev-Ops) for details.

## 3rd Party Packages
Expand Down Expand Up @@ -154,6 +163,11 @@ docker push hoseacodes/hoseacodes-blog:latest
git push heroku-staging HEAD:main
```

## How To Restart App

```bash
heroku restart -a app_name
```

## Unsolved Problems

Expand Down
102 changes: 94 additions & 8 deletions controllers/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ async function createArticle(req, res) {
medium,
postedBy,
series,
linkedin,
linkedinContent,
linkedinAccessToken,
} = req.body;

switch (req.body) {
Expand Down Expand Up @@ -134,10 +137,23 @@ async function createArticle(req, res) {
tags: ["api", "hoseacodes"],
categories,
slug: title.toLowerCase().replace(/ /g, "-"),
dev,
medium,
linkedin,
linkedinContent,
});

try {
if (dev) {
} catch (error) {
logger.error(error);
return res.status(error.response.status).json({
code: error.response.statusText,
msg: error.response.data,
});
}

if (dev) {
try {
if (!title || !markdown || !series) {
logger.error("No title, markdown or series provided.");
return res
Expand All @@ -164,9 +180,17 @@ async function createArticle(req, res) {
}
);
logger.info("Published to Dev To");
} catch (error) {
logger.error(error);
return res.status(error.response.status).json({
code: error.response.statusText,
msg: error.response.data,
});
}
}

if (medium) {
if (medium) {
try {
if (!series) {
logger.error("No series provided.");
return res.status(400).json({ msg: "No series upload" });
Expand All @@ -193,13 +217,75 @@ async function createArticle(req, res) {
}
);
logger.info("Published to Medium");
} catch (error) {
logger.error(error);
return res.status(error.response.status).json({
code: error.response.statusText,
msg: error.response.data,
});
}
}

if (linkedin) {
try {
const redirectUri = "http://localhost:3000/admin/blog/new";
const clientId = process.env.LINKEDIN_CLIENT_ID || "86s5czbllv0b9s";
const clientSecret =
process.env.LINKEDIN_CLIENT_SECRET || "VvcAdF8uDmIddv2J";
const getAccessToken = async () => {
const response = await axios.post(
"https://www.linkedin.com/oauth/v2/accessToken",
null,
{
params: {
grant_type: "authorization_code",
code: linkedinAccessToken,
redirect_uri: redirectUri,
client_id: clientId,
client_secret: clientSecret,
},
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}
);
return response.data.access_token;
};
const accessToken = await getAccessToken();
const response = await axios.post(
"https://api.linkedin.com/v2/ugcPosts",
{
author: `urn:li:person:ZGV337BIbm`,
lifecycleState: "PUBLISHED",
specificContent: {
"com.linkedin.ugc.ShareContent": {
shareCommentary: {
text: linkedinContent,
},
shareMediaCategory: "NONE",
},
},
visibility: {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC",
},
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
"X-Restli-Protocol-Version": "2.0.0",
"Content-Type": "application/json",
},
}
);
logger.info("Published to LinkedIn", { res: response.data });
} catch (error) {
logger.error(error);
console.log(error);
return res.status(error.response.status).json({
code: error.response.statusText,
msg: error.response.data,
});
}
} catch (error) {
logger.error(error);
return res.status(error.response.status).json({
code: error.response.statusText,
msg: error.response.data,
});
}

res.clearCookie("artilces-cache");
Expand Down
8 changes: 8 additions & 0 deletions models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ const articleSchema = new mongoose.Schema({
type: Boolean,
default: false,
},
linkedin: {
type: Boolean,
default: false,
},
linkedinContent: {
type: String,
default: null,
},
markdown: {
type: String,
required: true
Expand Down
Loading
Loading